GMT Vector Data Format and problems (Bad OGR/GMT)

I have the following simple file, which originally was converted from a shapefile with ogr2ogr and alot larger and more complex. I tried removing field after field to expose the offending data field, but even this cause problems:

# @VGMT1.0 @GPOINT
# @NName ID|Name Alias|MGDS_Featu|Vent Site
# @Tstring|string|string|string
# FEATURE_DATA
# @Da|a|a|a
7.58 77.63

Testing:

$ gmt psxy plume.gmt -JX10c -RNO > /dev/null
psxy [WARNING]: Bad OGR/GMT: @T record has more items than declared by @N - skipping
psxy [WARNING]: Bad OGR/GMT: @T record has more items than declared by @N - skipping
psxy [WARNING]: Bad OGR/GMT: @T record has more items than declared by @N - skipping
psxy [WARNING]: Bad OGR/GMT: @D record has more items than declared by @N
psxy [WARNING]: Bad OGR/GMT: @D record has more items than declared by @N
psxy [WARNING]: Bad OGR/GMT: @D record has more items than declared by @N

Should not this file run just fine? 4 attributes (@N), 4 definitions (@T) and 4 data fields (@D).

PS. Is the GMT vector data format driver (https://docs.generic-mapping-tools.org/latest/cookbook/ogrgmt-format.html) being maintained in ogr2ogr?

Hi Andreas,

yes, that does look a bit weird. I can reproduce the error messages with a recent trunk version of GMT 6 and this line:

gmt plot point_ogr.gmt -JX10c -RNO -Sc0.3 -Bafg -png ogr

Despite the script complaining, the map is generated fine. At first I thought that wrapping the attribute names in quotes might help but it does not make a difference.

I then tested getting rid of the spaces in your attribute names - e.g. Name ID to NameID and with that I don’t get error message anymore. So this seems to be that the OGR2GR driver doesn’t like spaces in the attribute names.

HTH,
Christian

Christian,

Thank you for testing. I also tried wrapping the names in quotes, but since that didnt work I didnt bother to remove the spaces. Nice catch!

I dont know if spaces are allowed.

Andreas

I have made this part more robust in GMT. I was/am under the impressions that string argument with spaces shall be inside double-quotes, but if I understand you correctly the ogr2ogr output did not have these quotes (?). The fix has been merged into master.
As far as I know, the GDAL team are maintaining all the drivers; the GMT/OGR was written by Frank Warnerdam.

Tested; gmt does not complain any longer - looks good, Paul!

I tested with two versions of ogr2ogr, GDAL 2.4.0, released 2018/12/14 and GDAL 3.1.4, released 2020/10/20. None of them put quotation marks in @N, even if the string argument contain spaces. Which caused problems, ref. Christians post. It will put double-quotes in @D if necessary.

Other improvements of the OGR_GMT driver between these two versions, for those interested:

  • Fix trailing space in @Jp: @Jp"+proj=longlat +datum=WGS84 +no_defs " --> @Jp"+proj=longlat +datum=WGS84 +no_defs"
  • Added info in @Jw: ,AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],
  • Pointless decimals are removed: 152.5 -60.0 --> 152.5 -60

Attached is the diff. Extension is zip but it’s a plain text file.

diff_gdal.2.4.0_vs_3.1.4.zip (1.3 KB)

Thanks Andreas, good to know!