Database Reference
In-Depth Information
# parameters
geocoder =
OSMGeocoder(db_connectionstring)
# here we query the geocode method,
for getting the geocoded points for the
# given placename
results = geocoder.geocode(placename)
print results
7. Now you can test the class by calling the script as shown:
(postgis-cb-env)$ python osmgeocoder.py
"Via Benedetto Croce"
"dbname=postgis_cookbook user=me
password=mypassword"[('Via Benedetto
Croce', 0.0, 'POINT(12.6999095325807
42.058016054317)'),...
8. So, now that you wrote a class that can be used to geocode street names,
let's suppose that another user wants to use it to geocode a file with a list
ofstreetnamesinordertoimportitinanewPostGISlayer.Hereishowthe
usercoulddothis(trythisaswell).First,createa streets.txt filewitha
list of street names, for example:
Via Delle Sette ChieseVia Benedetto
CroceLungotevere Degli InventoriViale
Marco Polo
Via Cavour
9. Nowcreateafilenamed geocode_streets.py ,andaddthisPythoncode
in it (you are going to use the OSMGeocoder class to geocode the street
namelist,andGDAL/OGRtocreateanewPostGISlayerforstoringthegeo-
coded points for the street names):
from osmgeocoder import OSMGeocoder
from osgeo import ogr, osr
# here we read the file
Search WWH ::




Custom Search