I am trying to geometry Python on a list of addresses stored in the table in PostGIS. I would like to set things so that each time the table is updated, and a new address is added, it will be automatically geocode (and then plotted on the map). The only way I could think of to do this was to create a geocoding function to use plpythonu, and then some combination of updates and triggers to get what I wanted. However, Pliptonu is actually doing strange work (I can ask about it later, but for now I'm looking for an alternative solution instead of searching for Pliptonu).
I can not think of any other way to set up, so if an entry is recorded in the database as soon as possible, is it geocode? Does anyone ask me to start some ideas from where?
Use one that modifies a line when it is inserted or updated. First, create a simple address geo encoding cover function by using a geopy
python 3 module:
Create or rearrange the function geocode_address (address text) returns Geometry AS $ Body $ import geopy from Geopy.geocoders import Nominatim geolocator = Nominatim () location = geolocator.geocode (address) location if: return 'srid = 4326; Point (% R% R) '% (location.logram, location.litidid) $ body $ language plpython3u optional 1000;
Check it out:
SELECT ST_Atext (geocode_address ('175 5th Avenue NYC'));
... POINT (-73.9366879 40.814044)
.
Should now be returned now you can use the function anywhere with this trigger function:
create or replace the function geocode_address_trigger () returns $ body $ BEGIN Trigger as NEW.geom: = geocode_address (NEW.address); Returns New; END; $ Body $ LANGUAGE plpgsql quantitative cost 100; Then apply trigger actions with then mytable
, address
and geom
fields.
Create mytable_geocode_address to create the trigger before the INR or update on mytable for each line geocode_address_trigger ();
Comments
Post a Comment