use data_geoid_colname for data, geom_geoid_colname for geom

This commit is contained in:
John Krauss 2016-05-11 15:47:29 -04:00
parent 56f4d2f256
commit aab24d00dd

View File

@ -213,12 +213,24 @@ DECLARE
query text; query text;
i int; i int;
geoid text; geoid text;
geoid_colname text; data_geoid_colname text;
geom_geoid_colname text;
area NUMERIC; area NUMERIC;
BEGIN BEGIN
-- TODO we're assuming our geom_table has only one geom_ref column -- TODO we're assuming our geom_table has only one geom_ref column
-- we *really* should pass in both geom_table_name and boundary_id -- we *really* should pass in both geom_table_name and boundary_id
EXECUTE
format('SELECT ct.colname
FROM observatory.obs_column_to_column c2c,
observatory.obs_column_table ct,
observatory.obs_table t
WHERE c2c.reltype = ''geom_ref''
AND ct.column_id = c2c.source_id
AND ct.table_id = t.id
AND t.tablename = %L'
, (data_table_info)[1]->>'tablename')
INTO data_geoid_colname;
EXECUTE EXECUTE
format('SELECT ct.colname format('SELECT ct.colname
FROM observatory.obs_column_to_column c2c, FROM observatory.obs_column_to_column c2c,
@ -229,15 +241,13 @@ BEGIN
AND ct.table_id = t.id AND ct.table_id = t.id
AND t.tablename = %L' AND t.tablename = %L'
, geom_table_name) , geom_table_name)
INTO geoid_colname; INTO geom_geoid_colname;
RAISE NOTICE 'geom_table_name: %', geom_table_name;
RAISE NOTICE 'colname: %', geoid_colname;
EXECUTE EXECUTE
format('SELECT %I format('SELECT %I
FROM observatory.%I FROM observatory.%I
WHERE ST_Within($1, the_geom)', WHERE ST_Within($1, the_geom)',
geoid_colname, geom_geoid_colname,
geom_table_name) geom_table_name)
USING geom USING geom
INTO geoid; INTO geoid;
@ -249,7 +259,7 @@ BEGIN
FROM observatory.%I FROM observatory.%I
WHERE %I = %L', WHERE %I = %L',
geom_table_name, geom_table_name,
geoid_colname, geom_geoid_colname,
geoid) geoid)
INTO area; INTO area;
@ -288,7 +298,7 @@ BEGIN
', ',
((data_table_info)[1])->>'tablename', ((data_table_info)[1])->>'tablename',
((data_table_info)[1])->>'tablename', ((data_table_info)[1])->>'tablename',
geoid_colname, data_geoid_colname,
geoid geoid
); );