GDAL Python OGRFeature .GetGeometryRef vs .Clone().GetGeometryRef

المشرف العام

Administrator
طاقم الإدارة
Just recently I was trying to get the geometry of a polygon stored in an ESRI Shapefile. In the script I was trying to read the polygon as follows:

import ogr path = "shape.shp" ds = ogr.Open(path, 0) layer = ds.GetLayer() layer.GetFeature(0).GetGeometryRef().GetGeometryName() which resulted in a memory access error.

I then tried this:

import ogr path = "shape.shp" ds = ogr.Open(path, 0) layer = ds.GetLayer() layer.GetFeature(0).Clone().GetGeometryRef().GetGeometryName() Which worked.

Why does that work but not the other approach? Which of them is 'right'?



أكثر...
 
أعلى