6

I have a series of shapefiles, that have 3D geometries (ie: points ZM). I would like to remove the 3D geometry so that the files are 2D. Is there a way to remove 3D geometry from a shapefile using OGR?

6
  • Technically, shapefiles with elevation values and measures are 4-D, not 3-D.
    – Vince
    Commented Oct 14, 2015 at 18:07
  • Is it enough to update Z and M to zero or do you want that the type of the shapefile is changed into POINT?
    – user30184
    Commented Oct 14, 2015 at 19:21
  • My preference would be to have the geometry as a point, not a pointZM Commented Oct 14, 2015 at 19:28
  • 3
    Then simply write a new shapefile as ogr2ogr -f "ESRI Shapefile" output_2d.shp input_zm.shp -dim 2 gdal.org/ogr2ogr.html. However, I do not know if it works if you really has POINTZM shapefile because GDAL does not support M gdal.org/drv_shapefile.html. Let's hope it just skips M values.
    – user30184
    Commented Oct 14, 2015 at 19:34
  • Thank you! I was wondering if the -dim was referencing geometry Commented Oct 14, 2015 at 19:44

2 Answers 2

15

Write your data into a new shapefile with ogr2ogr and force geometry type into 2D with the -dim switch.

ogr2ogr -f "ESRI Shapefile" output_2d.shp input_zm.shp -dim 2 

The -dim setting is not limited to shapefiles but works in the same way for most vector formats. One exception I know is Oracle Spatial that does not honour the ogr2ogr switch but you must use the layer specific -lco DIM=2instead.

http://gdal.org/ogr2ogr.html

http://www.gdal.org/drv_oci.html

3

Once your shapefile is read as ogr.Geometry, you can use its flattenTo2d() method.

See the GDAL documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.