[gdal-dev] Unable to use geom.ExportToWkt() in Python ?
Luke.Pinner at environment.gov.au
Tue Nov 23 22:04:32 EST 2010
You are running into a python "gotcha" -
Your reference to the feature is going out of scope when you use the
"firstgeom = layer.GetFeature(0).GetGeometryRef()" syntax. The
following works syntax fine:
feat = layer.GetFeature(0)
firstgeom = feat.GetGeometryRef()
From: gdal-dev-bounces at lists.osgeo.org
[mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Gregor at HostGIS
Sent: Wednesday, 24 November 2010 1:50 PM
To: Frank Warmerdam
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Unable to use geom.ExportToWkt() in Python ?
That's strange, the docs show ExportAsWkt as being a method of a
Geometry, as does the source code for the Python wrapper. Well, you
would know best...
If I do spatialref.ExportAsWkt() it gives the WKT of the SRS, right?
What if I want a feature's geometry? Would I need to generate it myself
from the geometry type and iterating over the vertices?
Sent from my Verizon Wireless Phone
----- Reply message -----
From: "Frank Warmerdam" <warmerdam at pobox.com>
Date: Tue, Nov 23, 2010 6:31 pm
Subject: [gdal-dev] Unable to use geom.ExportToWkt() in Python ?
To: "Gregor at HostGIS" <gregor at hostgis.com>
Cc: <gdal-dev at lists.osgeo.org>
Gregor at HostGIS wrote:
> Hey all. I am using the OGR binding for python, to open a SHP and
> a geometry's WKT. This works until I try to call geom.ExportToWkt() At
> that time I simply get "Premature end of script headers" Running it
> the command line I get a segmentation fault.
> The code snippet:
> driver = ogr.GetDriverByName('ESRI Shapefile')
> datasource = driver.Open(shapefile,0)
> layer = datasource.GetLayer()
> spatialRef = layer.GetSpatialRef()
> firstgeom = layer.GetFeature(0).GetGeometryRef()
> wkt = firstgeom.ExportToWkt()
Geometries do not have the ExportToWkt() method. This is a method on
the ogr.SpatialReference class.
wkt = spatialRef.ExportToWkt()
I set the clouds in motion - turn up | Frank Warmerdam,
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments.
Please consider the environment before printing this email.
More information about the gdal-dev