Skip to content

r3.info: Add JSON support #6103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2025
Merged

Conversation

NishantBansal2003
Copy link
Contributor

Fixes: #5995

This PR adds JSON support to the r3.info module. The changes include:

  1. Updated descriptions for all flags.
  2. Added a format option with plain, shell, and json modes for output formatting.
  3. For the -g and -r flags, the default formats remain shell and plain otherwise, to preserve backward compatibility.
  4. When no flag is given, two additional formats—shell and json—are now supported.
  5. For the -g and -r flags, plain and json output formats have been added.
  6. For the -h flag, a json output format have been added.
  7. Added tests covering each of the new formats.
  8. Added Python examples to the documentation, aligning it with the existing r.info module.

Below are example outputs for each format:

  • Example: shell output
layer=volume
date=Mon Jul 21 23:14:24 2025
mapset=PERMANENT
creator=nishantbansal
project=nc_spm_08_grass7
database=/grassdata
title=volume
units=none
vertical_units=units
timestamp="none"
maptype=raster_3d
ncats=0
datatype=DCELL
rows=100
cols=200
depths=50
cells=1000000
size=147591
ntiles=294
meansize=502
tilesize=31320
tilenumx=7
tilenumy=7
tilenumz=6
tiledimx=29
tiledimy=15
tiledimz=9
projection=Lambert Conformal Conic
zone=0
north=200
south=100
nsres=1
east=400
west=200
ewres=1
top=500
bottom=450
tbres=1
min=3
max=350
source1=""
source2=""
description="generated by r3.mapcalc"
comments="r3.mapcalc expression="volume = row() + col() + depth()" region="cur\rent""
  • Example: json output
{
    "layer": "volume",
    "date": "Mon Jul 21 23:14:24 2025",
    "mapset": "PERMANENT",
    "creator": "nishantbansal",
    "project": "nc_spm_08_grass7",
    "database": "/grassdata",
    "title": "volume",
    "units": "none",
    "vertical_units": "units",
    "timestamp": null,
    "maptype": "raster_3d",
    "ncats": 0,
    "datatype": "DCELL",
    "rows": 100,
    "cols": 200,
    "depths": 50,
    "cells": 1000000,
    "size": 147591,
    "ntiles": 294,
    "meansize": 502,
    "tilesize": 31320,
    "tilenumx": 7,
    "tilenumy": 7,
    "tilenumz": 6,
    "tiledimx": 29,
    "tiledimy": 15,
    "tiledimz": 9,
    "projection": "Lambert Conformal Conic",
    "zone": 0,
    "north": 200,
    "south": 100,
    "nsres": 1,
    "east": 400,
    "west": 200,
    "ewres": 1,
    "top": 500,
    "bottom": 450,
    "tbres": 1,
    "min": 3,
    "max": 350,
    "source1": "",
    "source2": "",
    "description": "generated by r3.mapcalc",
    "comments": "r3.mapcalc expression=\"volume = row() + col() + depth()\" region=\"current\""
}

For flag-specific output, see the tests in test_r3_info.py included with this PR.

Signed-off-by: Nishant Bansal <[email protected]>
@github-actions github-actions bot added Python Related code is in Python C Related code is in C module docs markdown Related to markdown, markdown files tests Related to Test Suite raster3d CMake labels Jul 23, 2025
Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just couple small suggestions.

Signed-off-by: Nishant Bansal <[email protected]>
@petrasovaa petrasovaa requested a review from cwhite911 July 25, 2025 11:36
@cwhite911 cwhite911 enabled auto-merge (squash) July 25, 2025 12:37
@cwhite911 cwhite911 merged commit 3ed9dd7 into OSGeo:main Jul 26, 2025
27 of 28 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in GRASS JSON Outputs Jul 26, 2025
@github-actions github-actions bot added this to the 8.5.0 milestone Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C CMake docs markdown Related to markdown, markdown files module Python Related code is in Python raster3d tests Related to Test Suite
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feat] Add JSON output to r3.info
3 participants