Plot shapefiles in X-Y coordinates

If you want ogr2ogr to do the projection to geographic (long-lat in degrees with WGS84 datum) coordinates, you can use the -t_srs EPSG:4326 option.

1 Like

I’ll try !

You may loose precision when reprojecting source UTM metric coordinates to WGS84 lat/lon degrees (by specifying -t_srs EPSG:4326). This may or may not matter (depending on the application and the size of the features as far as I can understand, most likely no problem for just an overview plotting). This may also be a reason NOT to convert .shp to GMT format as conversion from binary (.shp) to ASCII (,gmt) number representation may affect coordinate precision, while .shp to .shp simply copies over the coordinates in binary format (as far as I can understand).

you can also check all the distinct values of any parameter using ogrinfo and sql:
ogrinfo -sql "SELECT DISTINCT TERRE_MER FROM file_2154" file_2154.shp
this way ogrinfo shows all the distinct TERRE_MER values and feature count for each value.

Woow. That’s a nice feature, I was about to start some awk magic to extract these info… Thanks for the anticipation!

Yes these ogr (ogr/gdal) tools are sometimes absolutely invaluable when vector data come in databases like shapefiles. I’ve started learning these recently when like you I started working more and more with shapefile data and I use GMT for most of my plotting.

1 Like

well, if you have other tips and tricks, I’m all for it :slight_smile:

I’m currently working with polygon data (btw also UTM coordinates)

The first tip of the week is clipping closed multipolygon data to a closed polygon boundary producing new closed clipped polygons followed by area calculation for the clipped polygons:

org2ogr -clipsrc fjord_boundary.gmt -f GMT fjord_mud.gmt mud_polygons.gmt
orginfo -sql "SELECT SUM(OGR_GEOM_AREA) AS TOTAL_AREA FROM fjord_mud" fjord_mud.gmt

OGR_GEOM_AREA calculates area in the source coordinate units, so for my UTM data with metric coordinates the resulting area is in square meters.

The second tip of the week is producing polygon union for adjacent polygons (i.e. removing the internal boundaries):
ogr2ogr -sql "SELECT ST_UNION(GEOMETRY) FROM All_fjords" -dialect SQLite -f GMT Himmer.gmt All_fjords.gmt

1 Like