formatting

This commit is contained in:
Andy Eschbacher 2016-04-28 16:33:07 -07:00
parent ab93ff4ec0
commit 2325f97684

View File

@ -185,7 +185,7 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundaryById( CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundaryById(
geometry_id text, -- ex: '36047' geometry_id text, -- ex: '36047'
boundary_id text, -- ex: '"us.census.tiger".county' boundary_id text, -- ex: '"us.census.tiger".county'
time_span text DEFAULT NULL --ex: '2009' time_span text DEFAULT NULL -- ex: '2009'
) )
RETURNS geometry(geometry, 4326) RETURNS geometry(geometry, 4326)
AS $$ AS $$
@ -196,8 +196,8 @@ DECLARE
geom_colname text; geom_colname text;
BEGIN BEGIN
SELECT * INTO geoid_colname, target_table, geom_colname SELECT * INTO geoid_colname, target_table, geom_colname
FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id); FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id);
RAISE NOTICE '%', target_table; RAISE NOTICE '%', target_table;
@ -258,23 +258,23 @@ DECLARE
target_table text; target_table text;
BEGIN BEGIN
-- check inputs -- check inputs
IF lower(overlap_type) NOT IN ('contains', 'intersects', 'within') IF lower(overlap_type) NOT IN ('contains', 'intersects', 'within')
THEN THEN
-- recognized overlap type (map to ST_Contains, ST_Intersects, and ST_Within) -- recognized overlap type (map to ST_Contains, ST_Intersects, and ST_Within)
RAISE EXCEPTION 'Overlap type ''%'' is not an accepted type (choose contains, within, intersects)', overlap_type; RAISE EXCEPTION 'Overlap type ''%'' is not an accepted type (choose contains, within, intersects)', overlap_type;
ELSIF ST_GeometryType(geom) NOT IN ('ST_Polygon', 'ST_MultiPolygon') ELSIF ST_GeometryType(geom) NOT IN ('ST_Polygon', 'ST_MultiPolygon')
THEN THEN
RAISE EXCEPTION 'Invalid geometry type (%), expecting ''ST_MultiPolygon'' or ''ST_Polygon''', ST_GeometryType(geom); RAISE EXCEPTION 'Invalid geometry type (%), expecting ''ST_MultiPolygon'' or ''ST_Polygon''', ST_GeometryType(geom);
END IF; END IF;
-- TODO: add timespan in search -- TODO: add timespan in search
-- TODO: add overlap info in search -- TODO: add overlap info in search
-- TODO: turn this into a function _OBS_GetGeometryMetadata(geo_ref_name, tablename, and geom_colname) -- TODO: turn this into a function _OBS_GetGeometryMetadata(geo_ref_name, tablename, and geom_colname)
-- SELECT geo_ref_name, tablename, geom_colname INTO a, b, c -- SELECT geo_ref_name, tablename, geom_colname INTO a, b, c
-- FROM _OBS_GetGeometryMetadata -- FROM _OBS_GetGeometryMetadata
SELECT * INTO geoid_colname, target_table, geom_colname SELECT * INTO geoid_colname, target_table, geom_colname
FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id); FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id);
-- if no tables are found, raise notice and return null -- if no tables are found, raise notice and return null
IF target_table IS NULL IF target_table IS NULL
@ -377,19 +377,19 @@ DECLARE
target_table text; target_table text;
BEGIN BEGIN
IF lower(overlap_type) NOT IN ('contains', 'within', 'intersects') IF lower(overlap_type) NOT IN ('contains', 'within', 'intersects')
THEN THEN
RAISE EXCEPTION 'Overlap type ''%'' is not an accepted type (choose contains, within, intersects)', overlap_type; RAISE EXCEPTION 'Overlap type ''%'' is not an accepted type (choose contains, within, intersects)', overlap_type;
ELSIF ST_GeometryType(geom) NOT IN ('ST_Polygon', 'ST_MultiPolygon') ELSIF ST_GeometryType(geom) NOT IN ('ST_Polygon', 'ST_MultiPolygon')
THEN THEN
RAISE EXCEPTION 'Invalid geometry type (%), expecting ''ST_MultiPolygon'' or ''ST_Polygon''', ST_GeometryType(geom); RAISE EXCEPTION 'Invalid geometry type (%), expecting ''ST_MultiPolygon'' or ''ST_Polygon''', ST_GeometryType(geom);
END IF; END IF;
SELECT * INTO geoid_colname, target_table, geom_colname SELECT * INTO geoid_colname, target_table, geom_colname
FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id); FROM cdb_observatory._OBS_GetGeometryMetadata(boundary_id);
RAISE NOTICE 'geoid_colname: %, target_table: %, geom_colname: %', RAISE NOTICE 'geoid_colname: %, target_table: %, geom_colname: %',
geoid_colname, target_table, geom_colname; geoid_colname, target_table, geom_colname;
-- if no tables are found, raise notice and return null -- if no tables are found, raise notice and return null
IF target_table IS NULL IF target_table IS NULL
@ -462,30 +462,31 @@ RETURNS table(geoid_colname text, target_table text, geom_colname text)
AS $$ AS $$
BEGIN BEGIN
RETURN QUERY RETURN QUERY
EXECUTE EXECUTE
format($string$ format($string$
SELECT geoid_ct.colname As geoid_colname, SELECT geoid_ct.colname As geoid_colname,
tablename, tablename,
geom_ct.colname As geom_colname geom_ct.colname As geom_colname
FROM observatory.obs_column_table As geoid_ct, FROM observatory.obs_column_table As geoid_ct,
observatory.obs_table As geom_t, observatory.obs_table As geom_t,
observatory.obs_column_table As geom_ct, observatory.obs_column_table As geom_ct,
observatory.obs_column As geom_c observatory.obs_column As geom_c
WHERE geoid_ct.column_id WHERE geoid_ct.column_id
IN ( IN (
SELECT source_id SELECT source_id
FROM observatory.obs_column_to_column FROM observatory.obs_column_to_column
WHERE reltype = 'geom_ref' WHERE reltype = 'geom_ref'
AND target_id = '%s' AND target_id = '%s'
) )
AND geoid_ct.table_id = geom_t.id and AND geoid_ct.table_id = geom_t.id and
geom_t.id = geom_ct.table_id and geom_t.id = geom_ct.table_id and
geom_ct.column_id = geom_c.id and geom_ct.column_id = geom_c.id and
geom_c.type ILIKE 'geometry' geom_c.type ILIKE 'geometry'
-- TODO: filter by clipped vs. not so appropriate tablename are unique -- TODO: filter by clipped vs. not so appropriate tablename are unique
-- so the limit 1 can be removed -- so the limit 1 can be removed
LIMIT 1 LIMIT 1
$string$, boundary_id); $string$, boundary_id);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;