OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
853 stars 311 forks source link

[Feat] Add JSON output for history in v.info #4217

Open wenzeslaus opened 3 months ago

wenzeslaus commented 3 months ago

Is your feature request related to a problem? Please describe.

Printing vector map history with v.info using the h flag should work with format=json and produce JSON. Current state is:

$ grass --tmp-mapset ~/grassdata/nc_spm_08_grass7/ --exec v.info roadsmajor -h
COMMAND: v.in.ogr dsn="majorroads.shp" output="roads_major" min_area=0.0001 snap=-1
GISDBASE: /bigdata/grassdata05
LOCATION: wakestpfeet MAPSET: PERMANENT USER: helena DATE: Tue Nov  7 18:34:20 2006
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
COMMAND: v.proj input="wroads_major" location="wakestpfeet" output="roadsmajor_wake"
GISDBASE: /bigdata/grassdata05
LOCATION: ncfromfile MAPSET: PERMANENT USER: helena DATE: Wed Nov  8 00:18:50 2006
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
COMMAND: v.db.connect -o map="roadsmajor@PERMANENT" driver="sqlite" database="/home/neteler/grassdata/nc_spm_latest/nc_spm_08/PERMANENT/sqlite/sqlite.db" table="roadsmajor" key="cat" layer="1" separator="|"
GISDBASE: /home/neteler/grassdata/nc_spm_latest
LOCATION: nc_spm_08 MAPSET: PERMANENT USER: neteler DATE: Mon Nov 26 16:55:38 2012
---------------------------------------------------------------------------------
COMMAND: v.db.connect -o map="roadsmajor@PERMANENT" driver="sqlite" database="$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db" table="roadsmajor" key="cat" layer="1" separator="|"
GISDBASE: /home/neteler/grassdata
LOCATION: nc_spm_08_grass7 MAPSET: PERMANENT USER: neteler DATE: Fri Dec  7 23:25:12 2012

Describe the solution you'd like

Produce something like:

{
 "records": [
  {
   "command": "v.in.ogr...",
   "mapset_path": "...",
   "user": "..."
   "date": "..."
  },
  {
   "command": "v.proj...",
  }
 ]
}
data = gs.parse_command("r.info", map="lsat7_2002_30", format="json", flags="")
for record in data["records"]:
    print(record["command"]

Describe alternatives you've considered

Other schemas like list of commands separately for convenience (but context for reprojection might be missing). Database/project/mapset can be one mapset path (as above), as three keys database+project+mapset (path+project+mapset), or both.

Additional context

r.info -h tries to give similar information but the history is not stored in the same way for rasters at this point, so there is not much consistency or compatibility to consider.

NishantBansal2003 commented 1 month ago

Hey @wenzeslaus, do you want the JSON format and data to be structured like this?

{
  "records": [
    {
      "command": "v.in.ogr ...",
      "gisdbase": "/bigdata/grassdata05",
      "location": "wakestpfeet",
      "mapset": "PERMANENT",
      "user": "helena",
      "date": "Tue Nov  7 18:34:20 2006"
    },
    {
      "command": "v.proj ...",
      "gisdbase": "/bigdata/grassdata05",
      "location": "ncfromfile",
      "mapset": "PERMANENT",
      "user": "helena",
      "date": "Wed Nov  8 00:18:50 2006"
    },
    {
      "command": "v.db.connect ...",
      "gisdbase": "/home/neteler/grassdata/nc_spm_latest",
      "location": "nc_spm_08",
      "mapset": "PERMANENT",
      "user": "neteler",
      "date": "Mon Nov 26 16:55:38 2012"
    },
    {
      "command": "v.db.connect ...",
      "gisdbase": "/home/neteler/grassdata",
      "location": "nc_spm_08_grass7",
      "mapset": "PERMANENT",
      "user": "neteler",
      "date": "Fri Dec  7 23:25:12 2012"
    }
  ]
}

Is this the format you had in mind?

NishantBansal2003 commented 1 month ago

Hey @wenzeslaus, could you explain a bit about mapset_path, like what should be included here so I can start working on this? Thanks!