first pass obs_getmeasure
This commit is contained in:
parent
d6077457dd
commit
5e69297836
@ -400,6 +400,43 @@ BEGIN
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetMeasure(
|
||||
geom GEOMETRY,
|
||||
measure_id TEXT,
|
||||
normalize TEXT DEFAULT 'area', -- TODO denominator, none
|
||||
boundary_id TEXT DEFAULT NULL,
|
||||
time_span TEXT DEFAULT NULL
|
||||
)
|
||||
RETURNS JSON
|
||||
AS $$
|
||||
DECLARE
|
||||
names TEXT[];
|
||||
vals NUMERIC[];
|
||||
BEGIN
|
||||
|
||||
IF boundary_id IS NULL THEN
|
||||
-- TODO we should determine best boundary for this geom
|
||||
boundary_id := '"us.census.tiger".block_group';
|
||||
END IF;
|
||||
|
||||
IF time_span IS NULL THEN
|
||||
-- TODO we should determine latest timespan for this measure
|
||||
time_span := '2009 - 2013';
|
||||
END IF;
|
||||
|
||||
EXECUTE '
|
||||
SELECT names, vals FROM cdb_observatory._OBS_Get($1, ARRAY[$2], $3, $4) LIMIT 1
|
||||
'
|
||||
INTO names, vals
|
||||
USING geom, measure_id, time_span, boundary_id;
|
||||
|
||||
RETURN json_build_object('name', (names)[1], 'value', (vals)[1]);
|
||||
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetPolygons(
|
||||
geom geometry,
|
||||
geom_table_name text,
|
||||
@ -686,3 +723,4 @@ BEGIN
|
||||
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
@ -91,6 +91,16 @@ Done.
|
||||
{X10} |
|
||||
(1 row)
|
||||
|
||||
obs_getmeasure
|
||||
----------------------------------------------------
|
||||
{"name" : "total_pop", "value" : 9516.27915900609}
|
||||
(1 row)
|
||||
|
||||
obs_getmeasure
|
||||
----------------------------------------------------
|
||||
{"name" : "total_pop", "value" : 12140.2484103572}
|
||||
(1 row)
|
||||
|
||||
Dropping obs_table.sql fixture table...
|
||||
Done.
|
||||
Dropping obs_column.sql fixture table...
|
||||
|
@ -125,4 +125,19 @@ SELECT * FROM
|
||||
'"us.census.tiger".census_tract'
|
||||
);
|
||||
|
||||
-- Point-based OBS_GetMeasure, default normalization (area)
|
||||
SELECT * FROM
|
||||
cdb_observatory.OBS_GetMeasure(
|
||||
cdb_observatory._TestPoint(),
|
||||
'"us.census.acs".B01001001'
|
||||
);
|
||||
|
||||
-- Poly-based OBS_GetMeasure, default normalization (none)
|
||||
SELECT * FROM
|
||||
cdb_observatory.OBS_GetMeasure(
|
||||
cdb_observatory._TestArea(),
|
||||
'"us.census.acs".B01001001'
|
||||
);
|
||||
|
||||
|
||||
\i test/sql/drop_fixtures.sql
|
||||
|
Loading…
Reference in New Issue
Block a user