Is there a python library that can be used to make a line shapefile m-aware?

To be achieved only using python code and not arcpy libraries

closed as off-topic by PolyGeo Nov 11 at 4:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


I modified the code from gdal.VectorTranslate returns an empty file

from osgeo import gdal
openOptions = ['ADJUST_GEOM_TYPE=NO']
srcDS = gdal.OpenEx('input2dshp.shp',open_options=openOptions)
ds = gdal.VectorTranslate('output3dshp.shp', srcDS=srcDS, format = 'ESRI Shapefile', layerCreationOptions = ['SHPT=ARCM'])

#Dereference and close dataset, then reopen.
del ds
ds = gdal.OpenEx('output3dshp.shp',open_options=openOptions)

#Print geometry types


Then a test with ogrinfo. Read https://gdal.org/drivers/vector/shapefile.html and notice that because at this moment the geometries do not have M coordinates the open option is needed. Otherwise GDAL reads the first geometry and reports that geometries are just 2D.

ogrinfo output3dshp.shp -al -oo ADJUST_GEOM_TYPE=NO
INFO: Open of `output3dshp.shp'
      using driver `ESRI Shapefile' successful.

Layer name: output3dshp
Geometry: Measured Line String
Feature Count: 1
Extent: (270.000000, 350.000000) - (580.000000, 480.000000)
Layer SRS WKT:
FID: Integer64 (11.0)
  FID (Integer64) = 0
  LINESTRING M (270 368 -1.79769313486232e+308,508 350 -1.79769313486232e+308,580 480 -1.79769313486232e+308)

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