Database Reference
In-Depth Information
postgis_cookbook=# SELECT name, name <->
'via benedetto croce' AS weightFROM
chp08.osm_roadsORDER BY weight LIMIT
10;name |
weight------------------------+----------Via
Benedetto Croce | 0Via
Benedetto Croce | 0
...Via Benedetto XIV | 0.416667Via
Benedetto XIV | 0.416667
(10 rows)
5. We will use the last query as the SQL core of a Python class, which will
providegeocodingfeaturestotheconsumer,usingthelayerwejustimported
in PostGIS ( chp08.osm_roads ). First, create a file named osmgeo-
coder.py and add the following class to it:
import sys
import psycopg2
class OSMGeocoder(object):
"""
A class to provide geocoding features
using an OSM dataset in PostGIS.
"""
def __init__(self,
db_connectionstring):
# initialize db connection
parameters
self.db_connectionstring =
db_connectionstring
def geocode(self, placename):
"""
Geocode a given place name.
"""
# here we create the connection
object
Search WWH ::




Custom Search