9

It seems there is no geoalgorithm to drop z values in the QGIS processing toolbox. Can this be done programmatically using the Python console? At the moment I have to save the layer with unchecked 'Include z-dimension' checkbox (non automatic geometry type):

enter image description here

eclipsed_by_the_moon
  • 1,855
  • 21
  • 44
  • You could use the QgsVectorFileWriter.writeAsVectorFormat method (see for instance http://gis.stackexchange.com/questions/153309/qgis-export-shapefile-using-pyqgis/153318#153318 ). There is a includeZ parameter, but you won't need to pass it to the function because it's False by default. – Germán Carrillo Mar 14 '17 at 12:35

4 Answers4

12

For future reference - QGIS 3 includes a drop z value processing algorithm

ndawson
  • 27,620
  • 3
  • 61
  • 85
5

Specifically, the QGIS 3 tool is called Drop m/z values. It's in the Processing Toolbox, under Vector Geometry. The documentation is here:

https://docs.qgis.org/testing/en/docs/user_manual/processing_algs/qgis/vectorgeometry.html#qgisdropmzvalues

Justin Johnson
  • 311
  • 2
  • 5
1

Here is how i convert a QgsGeometry (geom) of type PolygonZ to a Polygon in the console:

new_geom = QgsGeometry().fromPolygonXY(geom.asPolygon())

It is some kind of workaround since there is no dedicated method for that. So i dont know if there are better ways to do it. Using the processing tool as recommended in the other answers would be the correct way if you want to convert a whole layer i guess.

Ah4b
  • 196
  • 1
  • 8
0

You can use ogr2ogr with -dim XY flag:

Force the coordinate dimension

See: https://gdal.org/programs/ogr2ogr.html#cmdoption-ogr2ogr-dim

BERA
  • 72,339
  • 13
  • 72
  • 161