I created a simple 1-feature polyline shapefile in QGIS 2.18. I would like to now read this shapefile in gdal
using python and extract its length.
I have done the following
import ogr
driver = ogr.GetDriverByName('ESRI Shapefile')
data_source = driver.Open('simple_line.shp')
layer = data_source.GetLayer()
line = layer.GetFeature(0).geometry()
line.Length()
The last line crashes python:
python.exe has stopped working
A problem caused the program to stop working correctly. Please close the program.
I guess it is to do with my shapefile since when I create a geometry using more "conventional" gdal
means I get the following:
import ogr
line = ogr.Geometry(ogr.wkbLineString)
line.AddPoint(1116651.439379124, 637392.6969887456)
line.AddPoint(1188804.0108498496, 652655.7409537067)
line.AddPoint(1226730.3625203592, 634155.0816022386)
line.AddPoint(1281307.30760719, 636467.6640211721)
line.Length()
The output to the above is 170573.31786365344
which implies it works.
What could be the reason that my shapefile-derived geometry object is crashing python?