Re: [gdal-dev] Unable to use geom.ExportToWkt() in Python ?

Gregor at HostGIS gregor at
Tue Nov 23 21:50:00 EST 2010

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>
Date: Tue, Nov 23, 2010 6:31 pm
Subject: [gdal-dev] Unable to use geom.ExportToWkt() in Python ?
To: "Gregor at HostGIS" <gregor at>
Cc: <gdal-dev at>

Gregor at HostGIS wrote:
> Hey all. I am using the OGR binding for python, to open a SHP and print 
> 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 from 
> 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.

Perhaps try:
   wkt = spatialRef.ExportToWkt()

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at
light and sound - activate the windows |
and watch the world go round - Rush    | Geospatial Programmer for Rent

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the gdal-dev mailing list