resolve issues in build and with code, now returning geometries and data as expected from obs_getoverpass

This commit is contained in:
John Krauss
2017-01-03 16:37:16 +00:00
parent ff50c5e2bf
commit 000a440417
5 changed files with 69 additions and 7 deletions

View File

@@ -684,11 +684,13 @@ BEGIN
Array_Cat(Array_Agg(geom_tablename),
Array_Agg(denom_tablename) FILTER (WHERE denom_tablename IS NOT NULL)))
)) tablename) bar) tablenames,
String_Agg(numer_tablename || '.' || numer_geomref_colname || ' = ' ||
geom_tablename || '.' || geom_geomref_colname ||
Coalesce(' AND ' || numer_tablename || '.' || numer_geomref_colname || ' = ' ||
denom_tablename || '.' || denom_geomref_colname, ''),
' AND ') AS obs_wheres,
String_Agg('ST_Intersects(' || geom_tablename || '.' || geom_colname
|| ', _geoms.geom)', ' AND ')
AS user_wheres

View File

@@ -1,7 +1,44 @@
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetOverpass(query text)
RETURNS table (lat Numeric, lon Numeric, "type" TEXT, id Numeric, tags TEXT) as $$
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetOverpass(
query text
) RETURNS TABLE (
geom TEXT,
"type" TEXT,
id TEXT,
properties TEXT
) AS $$
from observatory.osm import get_overpass
return get_overpass(query)
import plpy
import json
result = get_overpass(query)
return [{
'geom': json.dumps(feature['geometry']),
'type': feature['type'],
'id': str(feature['id']),
'properties': json.dumps(feature['properties'])
} for feature in result]
$$ LANGUAGE plpythonu;
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetOverpass(
query text
) RETURNS TABLE (
geom Geometry(Geometry, 4326),
"type" TEXT,
id TEXT,
properties JSON
) AS $$
BEGIN
RETURN QUERY
EXECUTE $string$
SELECT ST_GeomFromGeojson(geom) geom,
"type",
id,
properties::JSON
FROM cdb_observatory._OBS_GetOverPass($1)
$string$ USING query
RETURN;
END;
$$ LANGUAGE plpgsql;