Skip to content
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

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

Open
wenzeslaus opened this issue Aug 23, 2024 · 2 comments · May be fixed by #4989
Open

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

wenzeslaus opened this issue Aug 23, 2024 · 2 comments · May be fixed by #4989
Labels
C Related code is in C enhancement New feature or request

Comments

@wenzeslaus
Copy link
Member

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.

@wenzeslaus wenzeslaus added enhancement New feature or request C Related code is in C labels Aug 23, 2024
@NishantBansal2003
Copy link
Contributor

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
Copy link
Contributor

NishantBansal2003 commented Oct 28, 2024

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

@cwhite911 cwhite911 moved this to Todo in GRASS JSON Outputs Jan 23, 2025
@NishantBansal2003 NishantBansal2003 linked a pull request Jan 25, 2025 that will close this issue
@cwhite911 cwhite911 moved this from Todo to In Progress in GRASS JSON Outputs Jan 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 enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants