CREATE OR REPLACE FUNCTION outils.elevation("long" double precision, lat double precision) RETURNS double precision AS $BODY$ import urllib; page=urllib.urlopen('http://www.earthtools.org/height/'+str(lat)+'/'+str(long)); result_xml = page.READ() rv = plpy.execute("SELECT ((xpath('//height/meters/text()', '"+result_xml+"'::xml))[1])::text::float AS elevation") foo = rv[0]['elevation'] RETURN foo $BODY$ LANGUAGE plpythonu;
#!/bin/sh for a in `seq 1 20000`; do psql -c "UPDATE saisie.saisie_observation SET elevation = outils.elevation(st_x(st_transform(geometrie, 4326)), st_y(st_transform(geometrie, 4326))) WHERE id_entite IN (SELECT id_entite FROM saisie.saisie_observation WHERE elevation IS NULL AND GeometryType(geometrie) = 'POINT' ORDER BY id_entite LIMIT 1)" -h 192.168.1.230 -U nom_utilisateur nom_base_de_donnee # respect des conditions d'utilisation du service # interdisant plus d'une requête par seconde sleep 1; # echo "Élévation mise à jour" done