g.proj: add JSON support
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.
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 I have made the requested changes.
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 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
@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.cand 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!
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.
Are we even running build that use proj4?
According to configure.ac we support "PROJ.4.4.6 or later".
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 same issue here. I am no longer able to resolve conversations.
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?
Because of the open comments, when doing my rounds of PRs to merge, I didn't act on it.
@kritibirda26 will you please accept these changes so we can merge this PR.
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!
grass_parson needs to be added as dependency to:
https://github.com/OSGeo/grass/blob/c855d997fd574d1b3d8cd7afdaff087a1ca5ffd6/general/CMakeLists.txt#L25
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?
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.
@NishantBansal2003 Don't worry about the ProjJSON component now. Just do what was done here already and add the grass_parson dependency.
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.
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.
This can be closed, as it was completed in https://github.com/OSGeo/grass/pull/5419