Database Reference
In-Depth Information
f = open('streets.txt')
streets = f.read().splitlines()
f.close()
# here we create the PostGIS layer using
gdal/ogr
driver = ogr.GetDriverByName('PostgreSQL')
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
pg_ds = ogr.Open(
"PG:dbname='postgis_cookbook'
host='localhost' port='5432' user='me'
password='mypassword'", update = 1
)pg_layer =
pg_ds.CreateLayer('geocoded_points', srs
= srs, geom_type=ogr.wkbPoint,options = [
'GEOMETRY_NAME=the_geom',
'OVERWRITE=YES', # this will drop
and recreate the table every time
'SCHEMA=chp08',
])
# here we add the field to the PostGIS
layer
fd_name = ogr.FieldDefn('name',
ogr.OFTString)
pg_layer.CreateField(fd_name)
print 'Table created.'
# now we geocode all of the streets in
the file using the osmgeocoder class
geocoder =
OSMGeocoder('dbname=postgis_cookbook
user=me password=mypassword')
for street in streets:
print street
geocoded_street =
geocoder.geocode(street)[0]
print geocoded_street
Search WWH ::




Custom Search