# Plot shapefiles in X-Y coordinates

**URL:** <https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851>\
**Category:** Q&A\
**Created:** [April 26, 2022, 3:15pm UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851 "2022-04-26T15:15:41Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [April 26, 2022, 11:09pm UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/21 "2022-04-26T23:09:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [April 26, 2022, 11:20pm UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/22 "2022-04-26T23:20:15Z")

</div>

I’ll try !

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 27, 2022, 7:32am UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/23 "2022-04-27T07:32:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [April 27, 2022, 9:17am UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/24 "2022-04-27T09:17:50Z")

</div>

> [@mkononets](#):
>
> 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!

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 27, 2022, 9:40am UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/25 "2022-04-27T09:40:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [April 27, 2022, 10:07am UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/26 "2022-04-27T10:07:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 27, 2022, 11:43am UTC](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851/27 "2022-04-27T11:43:58Z")

</div>

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`

[Previous page](https://forum.generic-mapping-tools.org/t/plot-shapefiles-in-x-y-coordinates/2851.md?page=1)
