Generic Mapping Tools

From OpenStreetMap Wiki
Jump to navigation Jump to search
GMT example map derived from OSM data

"Generic Mapping Tools" (https://www.generic-mapping-tools.org) is the name of a set of generic mapping tools! The set contains programs for generating high-quality printable maps. They are being used mainly in scientific map making. Making maps with GMT normally includes writing a small shell-script containing a series of GMT commands drawing the different map layers and possibly a coordinate grid.

GMT input data

Input files for GMT are text or raster files in special formats; OSM xml data cannot be read directly. However, OSM data could be transformed to GMT-style text files directly via ad-hoc programs. It is further possible to use ESRI shapefile as intermediate format; shapefile conversion utilities are available for both OSM and GMT formats.

In addition, OSM data can be imported via osm2pgsql or similar tools into a PostGIS-enabled PostgreSQL database. With help of GDAL's ogr2ogr conversion utility [1], GMT layers can be produced by extracting database data with specific spatial SQL queries and writing them to GMT text files. ogr2ogr can perform any necessary coordinate transformations during the conversion process.

For each feature category displayed in the map, a separate GMT layer has to be created. The following commands extract different types of roads into two GMT text files and transform from Mercator projection to Lat/Long (the SQL query depends on the database layout; parameters for database access have to be adapted to the local PostgresSQL installation):

ogr2ogr -f "GMT" -s_srs 'EPSG:3857' -t_srs 'EPSG:4326' \
 -sql "select way from planet_osm_line where highway in ('primary', 'secondary', 'tertiary', 'unclassified', 'residential')" \
   roads01_example.gmt PG:"dbname=yourdatabase user=yourusername"
ogr2ogr -f "GMT" -s_srs 'EPSG:3857' -t_srs 'EPSG:4326' \
 -sql "select way from planet_osm_line where highway not in ('primary', 'secondary', 'tertiary', 'unclassified', 'residential')" \
  roads02_example.gmt PG:"dbname=yourdatabase user=yourusername"

Polygons can be obtained similarly:

ogr2ogr -f "GMT" -s_srs 'EPSG:3857' -t_srs 'EPSG:4326' \
 -sql "select way from planet_osm_polygon where \"natural\" like 'wetland'" \
   wetland_example.gmt PG:"dbname=yourdatabase user=yourusername"

It is probably recommendable to work with a database just covering the target region, or to restrict the output of ogr2ogr by other means.

GMT currently does not support unicode character encoding. Unicode input data for GMT's pstext command have to be converted (for example with GNU recode [2]) to latin-1 or other supported encodings.

GMT usage example

The resulting text files can be used as input to the GMT tool psxy; psbasemap draws map borders, scale bar and north arrow (coordinates, projection etc. have to be adapted to individual needs):

psxy -R-46.81/-46.77/-1.05/-1.015 -JM10c -K -m -W.7,black,- < roads02_example.gmt > output.eps
psxy -R-46.81/-46.77/-1.05/-1.015 -JM10c -O -K -m -W2p/0/0/0 < roads01_example.gmt >> output.eps
psxy -R-46.81/-46.77/-1.05/-1.015 -JM10c -O -K -m -W.7p/255/255/255 < roads01_example.gmt >> output.eps
psbasemap -R-46.81/-46.77/-1.05/-1.015 -JM10c -L-46.803/-1.046/-1.046/1 \ 
 -B1mf1mg1mwnES -T-46.807/-1.022/1 -O >> output.eps