Luke, you are so full of awesome. That page answers my question and has other good tips. Thank you so much.
Sent from my Verizon Wireless Phone ----- Reply message ----- From: "Pinner, Luke" <luke.pin...@environment.gov.au> Date: Tue, Nov 23, 2010 7:04 pm Subject: [gdal-dev] Unable to use geom.ExportToWkt() in Python ? [SEC=UNCLASSIFIED] To: "Gregor at HostGIS" <gre...@hostgis.com> Cc: <gdal-dev@lists.osgeo.org> You are running into a python "gotcha" - http://trac.osgeo.org/gdal/wiki/PythonGotchas 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() print firstgeom.ExportToWkt() Luke ________________________________ From: gdal-dev-boun...@lists.osgeo.org [mailto:gdal-dev-boun...@lists.osgeo.org] On Behalf Of Gregor at HostGIS Sent: Wednesday, 24 November 2010 1:50 PM To: Frank Warmerdam Cc: gdal-dev@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" <warmer...@pobox.com> Date: Tue, Nov 23, 2010 6:31 pm Subject: [gdal-dev] Unable to use geom.ExportToWkt() in Python ? To: "Gregor at HostGIS" <gre...@hostgis.com> Cc: <gdal-dev@lists.osgeo.org> 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() Gregor, 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, warmer...@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.
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev