If your going to do some OGR Python stuff, check out Fiona
http://pypi.python.org/pypi/Fiona/0.8 which is pretty nice API for working
with OGR in Python.

- Nathan
------------------------------
From: Tyler Mitchell
Sent: 19/03/2012 3:31 PM
To: OSGeo Discussions
Subject: Re: [OSGeo-Discuss] Need for to to convert/deconstruct a shapefile
to create a relational table


On 2012-03-18, at 6:46 PM, Stephen Woodbridge wrote:

Does this get you any closer to what you need:

SELECT OGR_GEOM_WKT, * FROM data;

-Steve


That's some nice ogr-foo to learn :)

Simon, it sounds like you could wrap this up pretty quickly in a python
script too.
A rough approach example:

from osgeo import ogr
ds = ogr.Open("/tmp/on_geoname.shp")
l1 = ds.GetLayerByIndex(0)
for f in range(l1.GetFeatureCount()):
 printme = []
 g1 = l1.GetFeature(f)
 for fld in range(g1.GetFieldCount()):
  printme.append(g1.GetFieldAsString(fld))
 gr1 = g1.GetGeometryRef()
 printme.append(str(gr1.GetX()) + "-" + str(gr1.GetY()))
 print printme

For what it's worth,
Tyler
_______________________________________________
Discuss mailing list
Discuss@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/discuss

Reply via email to