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.
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.
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.
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.
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.