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

**URL:** <https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416>\
**Category:** Q&A\
**Created:** [December 7, 2021, 10:40am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416 "2021-12-07T10:40:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 7, 2021, 10:40am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/1 "2021-12-07T10:40:43Z")

</div>

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](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](https://docs.generic-mapping-tools.org/dev/events.html)) about plotting polygons, but it was not clear to my how to best proceed.

---

<div class="post-metadata">

**Author:** ![chhei-s](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/chhei-s/32/1028_2.png) [@chhei-s](https://forum.generic-mapping-tools.org/u/chhei-s)\
**Post date:** [December 8, 2021, 9:12am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/2 "2021-12-08T09:12:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 8, 2021, 10:02am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/3 "2021-12-08T10:02:34Z")

</div>

Hi Christian,

Great tip. I’ll try this.

Thanks!

Andreas

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 9, 2021, 11:49am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/4 "2021-12-09T11:49:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [December 9, 2021, 3:24pm UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/5 "2021-12-09T15:24:37Z")

</div>

Possibly, this would have worked too

```auto
using GMT

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

```

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 9, 2021, 7:49pm UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/6 "2021-12-09T19:49:56Z")

</div>

Julia? Some day, Joaquim. Some day.

Thanks!

---

<div class="post-metadata">

**Author:** ![chhei-s](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/chhei-s/32/1028_2.png) [@chhei-s](https://forum.generic-mapping-tools.org/u/chhei-s)\
**Post date:** [December 13, 2021, 8:19am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/7 "2021-12-13T08:19:19Z")

</div>

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](https://geopackage.org) `*.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

---

<div class="post-metadata">

**Author:** ![brioglade](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/brioglade/32/1011_2.png) [@brioglade](https://forum.generic-mapping-tools.org/u/brioglade)\
**Post date:** [December 14, 2021, 12:26am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/8 "2021-12-14T00:26:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [December 14, 2021, 1:15am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/9 "2021-12-14T01:15:54Z")

</div>

As I told you [the other time](https://flint.soest.hawaii.edu/t/how-to-use-gmt-jl-in-colab/2126/2) I never used Colab. Why complicating? Just install in a normal machine.

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 14, 2021, 8:06am UTC](https://forum.generic-mapping-tools.org/t/can-gmt-read-well-known-text-making-movies-with-polygon-plotting/2416/10 "2021-12-14T08:06:39Z")

</div>

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.

- [https://gdal.org/user/sql\_sqlite\_dialect.html#spatialite-sql-functions](https://gdal.org/user/sql_sqlite_dialect.html#spatialite-sql-functions)
- [https://gis.stackexchange.com/questions/372391/ogrinfo-st-area-for-geopackage-returns-invalid-target-srid](https://gis.stackexchange.com/questions/372391/ogrinfo-st-area-for-geopackage-returns-invalid-target-srid)
