[Gdal-dev] help with OGR->python
sgillies at frii.com
Fri Feb 4 09:42:31 EST 2005
On Feb 3, 2005, at 7:06 PM, Dylan Beaudette wrote:
> After struggling with trying to get vector data into GMT with GRASS, I
> playing with the OGR bindings in python.
> however, after 2 hours I have not been able to do something as simple
> extract the geometry of polygons in a shapefile...
> I am trying to construct a small python program to convert a shapefile
> into a
> list of coordinates, with a few GMT-specific markers at the start of
> Does anyone know of an existing tool for this job? or perhaps some
> python code for reading a simply polygon shapefile?
> Thanks in advance!
It seems to me that the structure of an OGRGeometry is not exposed to
the ogr.py module. At least, when I
there is nothing that appears to provide access to the geometry's lines
and points. I could be wrong and hopefully Frank will clear this up.
You are also welcome to use my code at
which provides Python-friendly geometries that can be exchanged with
ogr.py by serializing to and from WKB format. like so:
ogr_feature = layer.GetNextFeature()
ogr_geom = ogr_feature.GetGeometryRef()
pcl_polygon = spatial.Polygon(wkb=ogr_geom.ExportToWkb())
for ring in pcl_polygon:
# process ring and points
Contact me offline about the spatial module so we don't go any further
OT on this list.
sgillies at frii dot com
More information about the Gdal-dev