Quantcast
Channel: Question and Answer » gdal
Viewing all articles
Browse latest Browse all 397

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

$
0
0

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’?


Viewing all articles
Browse latest Browse all 397

Trending Articles