Skip to content

Instantly share code, notes, and snippets.

@keum
Forked from bitner/pl elevation functions
Created June 14, 2016 21:33
Show Gist options
  • Save keum/3a4eba11d037d4208862f120006d92dd to your computer and use it in GitHub Desktop.
Save keum/3a4eba11d037d4208862f120006d92dd to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION public.dbs_ned_z(
IN text,
IN text,
OUT text)
RETURNS text AS
$BODY$
#!/bin/sh
url="http://ned.usgs.gov/epqs/pqs.php?output=json&x=$1&y=$2"; /usr/bin/curl -s $url
$BODY$
LANGUAGE plsh VOLATILE
COST 100;
CREATE OR REPLACE FUNCTION public.dbs_point_elevation(
IN geometry,
OUT double precision)
RETURNS double precision AS
$BODY$ SELECT (dbs_ned_z(st_x($1)::text,st_y($1)::text)::json->'USGS_Elevation_Point_Query_Service'->'Elevation_Query'->>'Elevation')::float8;$BODY$
LANGUAGE sql VOLATILE
COST 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment