Database Reference
In-Depth Information
Latitude is %s.' % (lng, lat))
plpy.info("SELECT
ST_GeomFromText('POINT(%s %s)', 4326)" %
(lng, lat))
result = plpy.execute("SELECT
ST_GeomFromText('POINT(%s %s)', 4326) AS
point_geocoded" % (lng, lat))
geometry =
result[0]["point_geocoded"]
return geometry
$$ LANGUAGE plpythonu;
2. After creating the function, try to test it:
postgis_cookbook=# SELECT
chp08.Geocode('Viale Ostiense 36, Rome');
INFO: Geocoded Via Ostiense, 36, 00154
Rome, Italy for the address: Viale
Ostiense 36, Rome
CONTEXT: PL/Python function "geocode"
INFO: Longitude is 12.480457, Latitude
is 41.874345.
CONTEXT: PL/Python function "geocode"
INFO: SELECT
ST_GeomFromText('POINT(12.480457
41.874345)', 4326)
CONTEXT: PL/Python function "geocode"
geocode
----------------------------------------------------
0101000020E6100000BF44BC75FEF52840E7357689EAEF4440
(1 row)
3. Now,youwillmakethefunctionalittlebitmoresophisticated.First,youwill
addanotherinputparametertolettheuserspecifythegeoocodeAPIengine
(defaulting to GoogleV3). Then, using the Python try...except block,
youwilltrytosetupsomekindoferrormanagementincasethegeopyGeo-
coder cannotmanageto return valid results for any reason:
Search WWH ::




Custom Search