Can gmt read well-known text? Making movies with polygon plotting

I want to create a movie using events plotting polygons.

The polygons have a start date and an end date. The polygons should appear at start date, and disappear at end date (so they have a duration). My data is delivered as a csv, with each row having a set of attributes and the geometry as well known text (https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry).

My hope was that I could use the same approach as I would with plotting points (i.e. row-by-row).

I don’t think it’s possible to read wkt with gmt, but if it is, how? Being able to process polygons on a row-by-row basis makes certain things easier.

I’ve looked at the events manpage (https://docs.generic-mapping-tools.org/dev/events.html) about plotting polygons, but it was not clear to my how to best proceed.

Hi Andreas,

I’d try and go the route via ogr2ogr with the layer creation option set to AS_XY (instead of wkt):

ogr2ogr -F OGR_GMT -lco GEOMETRY=AS_XY outfile.gmt infile.csv

This should then allow you to postprocess/read the file with GMT and do any magic you need for events. Depending on your workflow you should also be able to run SQL queries against your *.csv file during the conversion.

HTH,
Christian

Hi Christian,

Great tip. I’ll try this.

Thanks!

Andreas

Christian,

I ended up importing my data into an sqlite database.
I then do queries with ogr2ogr -F GMT -sql [..] to get what I want (changing dates in my case).
For each query I generate a new data file which is fed to gmt plot.
Pretty disk intensive I guess, but it works.

Thank you for the tip!

Andreas

Possibly, this would have worked too

using GMT

D = gmtread("that_CSV_file.csv", ogr=true);
1 Like

Julia? Some day, Joaquim. Some day.

Thanks!

Hi Andreas,

great ! I think the -sql option should also work with *.csv or *.shp files but SQLite of course also does the job. FWIW - the new Shapefile replacement Geopackage *.gpkg is a spatially-aware SQLite file (if you want to use your data with GIS like applications.

I guess similar to @Joaquim’s post, one could have done this in Python/PyGMT and geopandas, but as I assumed that you run events in a normal shell script and there ogr2ogr is likely the easiest option.

Cheers,
Christian

hi Joaquim,why I can’t install and use GMT.jl in Colab?

As I told you the other time I never used Colab. Why complicating? Just install in a normal machine.

Thanks again Christian.

I tried to find out what the difference is between ogr2ogr generated sqlite file and gpkg file (from a shapefile). I don’t quite understand it yet. It’s easy to get the geometry out of a gpkg file. I’m struggling to do the same with an sqlite file. I guess gpkg is the most convenient way to go as it is specifically made for spatial data.

I was also very pleased to see that you can access posgis functions like ST_Area, ST_Buffer etc. through SQL queries in ogr2ogr (via spatialite I guess). I did not know that this was possible.