[OSGeo-Discuss] Need for to to convert/deconstruct a shapefile to create a relational table

Tyler Mitchell tmitchell at osgeo.org
Sun Mar 18 22:31:16 PDT 2012


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/discuss/attachments/20120318/c341ba0f/attachment-0002.html>


More information about the Discuss mailing list