Skip to content

Support plotting OGR GeoJSON files #4599

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

Open
weiji14 opened this issue Dec 23, 2020 · 9 comments · May be fixed by #8719
Open

Support plotting OGR GeoJSON files #4599

weiji14 opened this issue Dec 23, 2020 · 9 comments · May be fixed by #8719
Labels
feature request Request a new feature

Comments

@weiji14
Copy link
Member

weiji14 commented Dec 23, 2020

Description of the desired feature

GeoJSON is a standard plaintext OGR format (https://gdal.org/drivers/vector/geojson.html) often used for web mapping and data interchange, and this file format is also rendered by GitHub natively (see https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository/mapping-geojson-files-on-github), making it an ideal format for sharing online.

There's some action at GenericMappingTools/pygmt#608 on integrating PyGMT with Geopandas, and being able to read GeoJSON directly into GMT plot would really help to simplify the coding! Currently GMT can read shapefiles (https://docs.generic-mapping-tools.org/6.1/cookbook/file-formats.html#shapefiles) via GDAL, but it would be nice to extend this to the GeoJSON format (this is a smaller scope than full OGR vector support as in #3013).

Are you willing to help implement and maintain this feature? When I pick up C programming 🙂

@weiji14 weiji14 added the feature request Request a new feature label Dec 23, 2020
@joa-quim
Copy link
Member

joa-quim commented Dec 23, 2020

Wei Ji, the fact is that GMT can already read them (see gmt_ogrread.c) but it lacks the ability to convert the data into its internal data structures. So in practice this feature is not yet accessible. Except from Julia where I do the data parsing in the Julia side.

@weiji14
Copy link
Member Author

weiji14 commented Mar 5, 2021

Just following up on this because I'm working on a PR at GenericMappingTools/pygmt#1000. What is required to convert GeoJSON (or any OGR format) data to GMT's internal data structures? I had a read through #3013 again but couldn't really understand what needs to be done.

Thought I'd give some test cases too (remove the .txt extension after downloading):

data.gmt.txt

gmt info data.gmt -C
# 0	35	0	20

data.geojson.txt

gmt info data.geojson -C
# gmtinfo [ERROR]: No data columns to work with - exiting
# gmtinfo [ERROR]: Data file only has trailing text. GMT expects numerical columns followed by optional trailing text

@joa-quim
Copy link
Member

joa-quim commented Mar 5, 2021

Wei Ji, #3013 is only marginally related to support reading all the OGR formats. It's something we need if we want to keep information about geometries but we could live without it. The big issue is that the GMT IO is complicated and by GMT's internal data structures I mean having to do programming like this and below. That is, to get the data from GDAL and translate it to fill all of those Dataset->table, Dataset->Segments, ...

@joa-quim
Copy link
Member

joa-quim commented Mar 5, 2021

And BTW, in Julia I get this

D = gmtread("data.geojson");
plot(D, show=true)

ex

@joa-quim
Copy link
Member

This is a know issue that needs a more general approach.

@seisman
Copy link
Member

seisman commented Apr 23, 2025

Should we reconsider this feature request, considering that GeoJSON is a commonly used format?

Ideally we should read the GeoJSON file and convert it to GMT's internal data structure, as mentioned above, but it's technically challenging. Shapefiles are supported by converting shapefiles to OGR_GMT format via ogr2ogr calls. The same approach can be applied to GeoJSON files. I've submitted a PR at #8719.

@seisman seisman reopened this Apr 23, 2025
@anbj
Copy link
Contributor

anbj commented Apr 23, 2025

I agree - but doesnt this apply to all formats not supported by GMT, but supported by ogr2ogr?
Why not do this with all formats understood by ogr2ogr?

@anbj
Copy link
Contributor

anbj commented Apr 23, 2025

Maybe we should remove support for shapefiles instead.. http://switchfromshapefile.org/.

@joa-quim
Copy link
Member

We could add more (gpkg for instance) but I'm not particular proud in this GMT solution and a bit reluctant in advertising it for more formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants