How to do it...

Carry out the following steps:

  1. As the first test, open your favorite SQL client (psql or pgAdmin), and write a very basic PL/Python function, just using the GoogleV3 geocoding API with geopy. The function will accept the address string as an input parameter and, after importing geopy, it will instantiate a geopy Google Geocoder, run the geocode process, and then return the point geometry, using the ST_GeomFromText function and the geopy output:
        CREATE OR REPLACE FUNCTION chp08.Geocode(address text)          RETURNS geometry(Point,4326) AS $$          from geopy import geocoders          g = geocoders.GoogleV3()          place, (lat, lng) = g.geocode(address)          plpy.info('Geocoded %s for the address: %s' % (place, address)) plpy.info('Longitude is %s, Latitude ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.