grass icon indicating copy to clipboard operation
grass copied to clipboard

g.proj: add JSON support

Open kritibirda opened this issue 1 year ago • 7 comments

Use parson to add JSON support to g.proj. Currently, only works with the -p flag.

{
    "name": "Lambert Conformal Conic",
    "proj": "lcc",
    "datum": "nad83",
    "a": "6378137.0",
    "es": "0.006694380022900787",
    "lat_1": "36.16666666666666",
    "lat_2": "34.33333333333334",
    "lat_0": "33.75",
    "lon_0": "-79",
    "x_0": "609601.22",
    "y_0": "0",
    "no_defs": "defined",
    "srid": "EPSG:3358",
    "unit": "Meter",
    "units": "Meters",
    "meters": "1"
}

I tried to add support for some other flags as well but it seems the SHELL/PLAIN output needs to be parsed manually to obtain the data and there is no direct way to obtain the data directly, for instance for w flag.

Also, some floats are represented as strings at the moment and need to be fixed.

kritibirda avatar Jul 25 '24 18:07 kritibirda

For the proj4 format flag -j and the WKT format flag -w you can just return the the flattened (flag -f) string to the json.

{
   "wtk": "string_value",
   "proj4": "string_value"
}

cwhite911 avatar Jul 27 '24 18:07 cwhite911

@cwhite911 I have made the requested changes.

kritibirda avatar Aug 03 '24 19:08 kritibirda

From @florisvdh on issue https://github.com/OSGeo/grass/issues/3020

Adding here that the preferred JSON encoding for g.proj output would be the PROJJSON specification: https://proj.org/en/latest/specifications/projjson.html. It's a JSON encoding of WKT2:2019.

cwhite911 avatar Aug 11 '24 18:08 cwhite911

@cwhite911 I tried to update the output to use projjson specification, however there seem to be a lot of cases to handle. IIUC, there are 3 different major versions (4/5/6) of proj4 that need to be handled separately and another case of not having libproj4 but using internal Grass GIS functions. FWIW, libproj4 starting with v6 exposes a function to generate the projjson representation directly.

While reading the code in get_proj.c and related files, I saw some comments about a future cleanup of proj4 versions. I think it would be better to handle add the proper JSON representation of proj4 here at that stage.

kritibirda avatar Aug 21 '24 05:08 kritibirda

@kritibirda26

@cwhite911 I tried to update the output to use projjson specification, however there seem to be a lot of cases to handle. IIUC, there are 3 different major versions (4/5/6) of proj4 that need to be handled separately and another case of not having libproj4 but using internal Grass GIS functions. FWIW, libproj4 starting with v6 exposes a function to generate the projjson representation directly.

While reading the code in get_proj.c and related files, I saw some comments about a future cleanup of proj4 versions. I think it would be better to handle add the proper JSON representation of proj4 here at that stage.

@kritibirda26 that sounds good to me. Thanks for looking into it!

cwhite911 avatar Aug 26 '24 19:08 cwhite911

Are we even running build that use proj4? I only remember seeing proj 5+ api at the end of configure, and now Proj is at 9.4 now.

echoix avatar Aug 26 '24 22:08 echoix

Are we even running build that use proj4?

According to configure.ac we support "PROJ.4.4.6 or later".

neteler avatar Aug 27 '24 08:08 neteler

Do we want to go forward finishing up and merging the existing json PRs kinda soon? since some work is being done to implement on other modules too.

echoix avatar Nov 07 '24 22:11 echoix

@echoix same issue here. I am no longer able to resolve conversations.

cwhite911 avatar Jan 23 '25 18:01 cwhite911

Ok, resolved them. Do you think the tests failures are transient and I should update the PR, or there's some real changes to do?

echoix avatar Jan 23 '25 18:01 echoix

Because of the open comments, when doing my rounds of PRs to merge, I didn't act on it.

echoix avatar Jan 23 '25 18:01 echoix

@kritibirda26 will you please accept these changes so we can merge this PR.

cwhite911 avatar Jan 23 '25 21:01 cwhite911

Ok, resolved them. Do you think the tests failures are transient and I should update the PR, or there's some real changes to do?

Real changes. Nice catch @echoix!

cwhite911 avatar Jan 23 '25 21:01 cwhite911

grass_parson needs to be added as dependency to:

https://github.com/OSGeo/grass/blob/c855d997fd574d1b3d8cd7afdaff087a1ca5ffd6/general/CMakeLists.txt#L25

nilason avatar Feb 26 '25 18:02 nilason

Hey @cwhite911, can you clarify a bit about the PROJJSON specification? I'm looking for an example of what it should look like with the existing data, as I didn't completely understand what and how things should be added to the JSON format. Or should I just use the existing JSON structure, add tests, and update the docs?

NishantBansal2003 avatar Mar 19 '25 14:03 NishantBansal2003

Hey @cwhite911, can you clarify a bit about the PROJJSON specification? I'm looking for an example of what it should look like with the existing data, as I didn't completely understand what and how things should be added to the JSON format. Or should I just use the existing JSON structure, add tests, and update the docs?

I think the PROJJSON is out of scope.

petrasovaa avatar Mar 19 '25 17:03 petrasovaa

@NishantBansal2003 Don't worry about the ProjJSON component now. Just do what was done here already and add the grass_parson dependency.

cwhite911 avatar Mar 19 '25 19:03 cwhite911

Hi @cwhite911! Sorry for the very late reply. I will reach out in an email explaining it later but for now I am available to finish this PR.

kritibirda avatar Mar 20 '25 12:03 kritibirda

Hi @kritibirda26, good to see you back! @NishantBansal2003 has been tying the loose ends of the open JSON PRs. He opened already a PR (#5419) for this (with added documentation) so we will probably continue there and close this one. But I see you were active in the other 2 open PRs, so @NishantBansal2003 please leave these for @kritibirda26 to finish. I am aware we are due reviews there, bare with us.

petrasovaa avatar Mar 20 '25 14:03 petrasovaa

This can be closed, as it was completed in https://github.com/OSGeo/grass/pull/5419

NishantBansal2003 avatar Apr 06 '25 04:04 NishantBansal2003