Merge branch 'develop' into iss66-cast-geom-ids-to-text

This commit is contained in:
Andy Eschbacher
2016-05-17 11:09:10 -04:00
21 changed files with 15439 additions and 16223 deletions

View File

@@ -39,7 +39,7 @@ AS $$
boundary_id = 'us.census.tiger.block_group';
END IF;
target_cols := Array['us.census.acs.B01001001',
target_cols := Array['us.census.acs.B01003001',
'us.census.acs.B01001002',
'us.census.acs.B01001026',
'us.census.acs.B01002001',
@@ -172,6 +172,7 @@ BEGIN
RAISE NOTICE 'Point % is outside of the data region', ST_AsText(geom);
-- TODO this should return JSON
RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[];
RETURN;
END IF;
IF data_table_info IS NULL THEN
@@ -198,6 +199,7 @@ BEGIN
SELECT unnest($1)
$query$
USING results;
RETURN;
END;
$$ LANGUAGE plpgsql;
@@ -356,11 +358,11 @@ BEGIN
' INTO denominator_id
USING measure_id;
measure_ids := ARRAY[measure_id, denominator_id];
ELSIF normalize IS NULL OR normalize ILIKE 'none' THEN
ELSIF normalize ILIKE 'none' THEN
-- TODO we need a switch on obs_get to disable area normalization
RAISE EXCEPTION 'No normalization not yet supported.';
ELSE
RAISE EXCEPTION 'Only valid inputs for "normalize" are "area" (default), "denominator", or "none".';
RAISE EXCEPTION 'Only valid inputs for "normalize" are "area" (default) and "denominator".';
END IF;
EXECUTE '
@@ -398,7 +400,7 @@ BEGIN
IF time_span IS NULL THEN
-- TODO we should determine latest timespan for this measure
time_span := '2009 - 2013';
time_span := '2010 - 2014';
END IF;
EXECUTE '
@@ -492,7 +494,7 @@ DECLARE
result NUMERIC;
BEGIN
-- TODO use a super-column for global pop
population_measure_id := 'us.census.acs.B01001001';
population_measure_id := 'us.census.acs.B01003001';
EXECUTE format('SELECT cdb_observatory.OBS_GetMeasure(
%L, %L, %L, %L, %L
@@ -602,7 +604,7 @@ IF boundary_id IS NULL THEN
boundary_id = 'us.census.tiger.census_tract';
END IF;
target_cols := Array[
'us.census.acs.B01001001_quantile',
'us.census.acs.B01003001_quantile',
'us.census.acs.B01001002_quantile',
'us.census.acs.B01001026_quantile',
'us.census.acs.B01002001_quantile',
@@ -668,7 +670,7 @@ target_cols := Array[
array_agg(_OBS_GET->>'value') As vals
FROM cdb_observatory._OBS_Get($1,
$2,
'2009 - 2013',
'2010 - 2014',
$3)
), percentiles As (
@@ -709,7 +711,7 @@ DECLARE
BEGIN
IF time_span IS NULL THEN
time_span = '2009 - 2013';
time_span = '2010 - 2014';
END IF;
IF boundary_id IS NULL THEN
@@ -722,6 +724,7 @@ BEGIN
THEN
RAISE NOTICE 'Point % is outside of the data region', ST_AsText(geom);
RETURN QUERY SELECT '{}'::text[], '{}'::text[];
RETURN;
END IF;
EXECUTE '
@@ -735,6 +738,7 @@ BEGIN
THEN
RAISE NOTICE 'No data table found for this location';
RETURN QUERY SELECT NULL::json;
RETURN;
END IF;
EXECUTE
@@ -749,6 +753,7 @@ BEGIN
THEN
RAISE NOTICE 'No geometry id for this location';
RETURN QUERY SELECT NULL::json;
RETURN;
END IF;
query := 'SELECT ARRAY[';

View File

@@ -15,7 +15,7 @@ BEGIN
THEN
RETURN QUERY
EXECUTE
'SELECT tablename, timespan
'SELECT tablename::text, timespan::text
FROM observatory.obs_table t
JOIN observatory.obs_column_table ct
ON ct.table_id = t.id
@@ -24,10 +24,11 @@ BEGIN
WHERE c.type ILIKE ''geometry''
AND c.id = $1'
USING search_term;
RETURN;
ELSE
RETURN QUERY
EXECUTE
'SELECT tablename, timespan
'SELECT tablename::text, timespan::text
FROM observatory.obs_table t
JOIN observatory.obs_column_table ct
ON ct.table_id = t.id
@@ -37,6 +38,7 @@ BEGIN
AND c.id = $1
AND t.timespan = $2'
USING search_term, time_span;
RETURN;
END IF;
END;
@@ -63,9 +65,9 @@ BEGIN
RETURN QUERY
EXECUTE format($string$
SELECT id, description,
name,
aggregate,
SELECT id::text, description::text,
name::text,
aggregate::text,
NULL::TEXT source -- TODO use tags
FROM observatory.OBS_column
where name ilike '%%' || %L || '%%'
@@ -98,10 +100,10 @@ BEGIN
EXECUTE
$string$
SELECT
column_id,
obs_column.description,
timespan,
tablename
column_id::text As column_id,
obs_column.description::text As description,
timespan::text As timespan,
tablename::text As tablename
FROM
observatory.OBS_table,
observatory.OBS_column_table,

View File

@@ -119,7 +119,7 @@ BEGIN
-- If not point, raise error
IF ST_GeometryType(geom) != 'ST_Point'
THEN
RAISE EXCEPTION 'Error: Invalid geometry type (%), expecting ''ST_Point''', ST_GeometryType(geom);
RAISE EXCEPTION 'Invalid geometry type (%), expecting ''ST_Point''', ST_GeometryType(geom);
END IF;
-- choose appropriate table based on time_span
@@ -143,7 +143,7 @@ BEGIN
-- if no tables are found, raise notice and return null
IF target_table IS NULL
THEN
RAISE NOTICE 'No boundaries found for ''%''', boundary_id;
RAISE NOTICE 'Warning: No boundaries found for ''%''', boundary_id;
RETURN NULL::text;
END IF;
@@ -545,9 +545,9 @@ BEGIN
RETURN QUERY
EXECUTE
format($string$
SELECT geoid_ct.colname As geoid_colname,
tablename,
geom_ct.colname As geom_colname
SELECT geoid_ct.colname::text As geoid_colname,
tablename::text,
geom_ct.colname::text As geom_colname
FROM observatory.obs_column_table As geoid_ct,
observatory.obs_table As geom_t,
observatory.obs_column_table As geom_ct,
@@ -569,6 +569,7 @@ BEGIN
-- AND geom_t.timespan = '%s' <-- put in requested year
-- TODO: filter by clipped vs. not so appropriate tablename are unique
-- so the limit 1 can be removed
RETURN;
END;
$$ LANGUAGE plpgsql;