Our introduction to spatial databases is almost complete; the only thing left to examine is how to get spatial data out of PostGIS again, for example to save it back into a shapefile. To extract a spatial value from a GEOGRAPHY
field, use the ST_AsText()
function. For example:
cursor.execute("SELECT name,ST_AsText(outline) FROM borders") for name,wkt in cursor: geometry = osgeo.ogr.CreateGeometryFromWkt(wkt) ...
You can then use the OGR geometry to write the spatial data into a shapefile, or do anything else you wish to do with it.