Database Reference
In-Depth Information
er parameters as well such as dimension ( 3 , as you want to store the z values),
GEOMETRY_NAME (thenameofthegeometricfield ) and schema .Aftercreatingthe
layer, you can use the CreateField layer method to create all the fields that are
neededtostoretheinformation.Eachfieldwillhaveaspecific name and datatype
(all of them are ogr.OFTString for this case).
After the layer has been created (note that we need to have the pg_ds and
pg_layer objects always in context for the whole script, as noticed at ht-
tp://trac.osgeo.org/gdal/wiki/PythonGotchas ), you can query the GeoNames Web
services for each place name in the names.txt file using the urllib2 library.
We parsed the JSON response using the simplejson library, then iterated the
JSONobjectslist,andaddedafeaturetothePostGISlayerforeachoftheobjects
in the JSON output. For each element, we created a feature with a point wkt
geometry (using the lng , lat , and elevation object attributes) using the
ogr.CreateGeometryFromWkt method, and updated the other fields using the
otherobjectattributesreturnedbyGeoNamesusingthefeature setField method
( title , countryCode , and so on).
YoucangetmoreinformationonprogrammingwithGDALPythonbindingsusingthe
following great resource by Chris Garrard:
http://www.gis.usu.edu/~chrisg/python/2009/
Search WWH ::




Custom Search