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
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
I modified the code from gdal.VectorTranslate returns an empty file
from osgeo import gdal
gdal.UseExceptions()
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
print(srcDS.GetLayer(0).GetGeomType())
print(ds.GetLayer(0).GetGeomType())
Result:
2
2002
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
Metadata:
DBF_DATE_LAST_UPDATE=2019-10-16
Geometry: Measured Line String
Feature Count: 1
Extent: (270.000000, 350.000000) - (580.000000, 480.000000)
Layer SRS WKT:
(unknown)
FID: Integer64 (11.0)
OGRFeature(output3dshp):0
FID (Integer64) = 0
LINESTRING M (270 368 -1.79769313486232e+308,508 350 -1.79769313486232e+308,580 480 -1.79769313486232e+308)