1

I have a couple of Shapefiles which are of geometry type ZM (like PolygonZM, MultiLineStringZM, etc.), however my database (a PostGIS database) is of geometry type Z (like PolygonZ, MultiPointZ, etc.). When I import my shapefile into database, it will of course report an error. However, when I convert these Shapefiles, I find that M values cannot be removed without removing Z value.
Here are my efforts:
1. In ArcMap, use Feature Class to Feature Class in ArcToolbox, click "Environment" and disable M value there. However, output Shapefiles still have M values.
2. Using Export in QGIS, and choose PolygonZ or other geometry types with Z only in SHPT field. Again, output Shapefiles still have M values.
3. Use ogr2ogr. Here is the command line:

ogr2ogr -nlt polygonz new.shp old.shp

Again, output Shapefiles still have M values.
However, if I discard Z values as well:

ogr2ogr -nlt polygon new.shp old.shp

Output Shapefiles will have neither Z nor M values.
But when I try to add Z again, like:

ogr2ogr -nlt polygonz new1.shp new.shp

Both Z and M will be added, thus returning to PolygonZM.
Since these shapefiles have no actual Z values at all, I can safely discard Z values along with M values if I only need to deal with these files themselves. However, in my database, geometry columns are storing Z values, and they cannot be discarded. Can anyone tell me why can't I just discard M values and preserve Z values for these Shapefiles?

  • 1
    Copy features tool with M disabled? – FelixIP Apr 4 at 7:26
  • Yes, it works fine, just tested it again to be sure. – FelixIP Apr 4 at 7:39
  • perhaps a workaround would be to add the z values to the attribute table – csk Apr 5 at 18:19
2

Shapefiles with Z contain also always M. See the technical specification of PointZ from https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf. Same applies to other geometry types with Z.

A PointZ consists of a triplet of double-precision coordinates in the order X, Y, Z plus a measure.

PointZ
{
Double X  //X coordinate
Double Y  //Y coordinate
Double Z  //Z coordinate
Double M  //M measure
}

You can drop M when you convert data into PostGIS with ogr2ogr just as you tried to drop it from the shapefile with -nlt polygonz.

  • Maybe it's a shame for me, who worked in GIS for about five years, have not ever read the definition of shapefile... – Aurus Huang Apr 4 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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