support POINT and LINESTRING types from obs_getboundaries

This commit is contained in:
John Krauss 2016-12-29 17:07:38 +00:00
parent 7adbad602e
commit 39eb031316
6 changed files with 238 additions and 12 deletions

View File

@ -187,6 +187,8 @@ FIXTURES = [
('us.census.tiger.zcta5_clipped', 'us.census.tiger.zcta5_clipped', '2014'), ('us.census.tiger.zcta5_clipped', 'us.census.tiger.zcta5_clipped', '2014'),
('us.census.tiger.block_group_clipped', 'us.census.tiger.block_group_clipped', '2014'), ('us.census.tiger.block_group_clipped', 'us.census.tiger.block_group_clipped', '2014'),
('us.census.tiger.census_tract_clipped', 'us.census.tiger.census_tract_clipped', '2014'), ('us.census.tiger.census_tract_clipped', 'us.census.tiger.census_tract_clipped', '2014'),
('us.census.tiger.pointlm', 'us.census.tiger.pointlm', '2016'),
('us.census.tiger.prisecroads', 'us.census.tiger.prisecroads', '2016'),
] ]
OUTFILE_PATH = os.path.join(os.path.dirname(__file__), '..', OUTFILE_PATH = os.path.join(os.path.dirname(__file__), '..',
@ -322,6 +324,10 @@ def main():
if 'zcta5' in boundary_id: if 'zcta5' in boundary_id:
where = '\'11%\'' where = '\'11%\''
compare = 'LIKE' compare = 'LIKE'
elif boundary_id in ('us.census.tiger.prisecroads',
'us.census.tiger.pointlm'):
dump('*', tablename, 'WHERE geom && ST_MakeEnvelope(-74,40.69,-73.9,40.72, 4326)')
continue
elif 'whosonfirst' in boundary_id: elif 'whosonfirst' in boundary_id:
where = '(\'85632785\',\'85633051\',\'85633111\',\'85633147\',\'85633253\',\'85633267\')' where = '(\'85632785\',\'85633051\',\'85633111\',\'85633147\',\'85633253\',\'85633267\')'
compare = 'IN' compare = 'IN'

View File

@ -148,16 +148,16 @@ BEGIN
END IF; END IF;
EXECUTE EXECUTE
format('SELECT ct.colname 'SELECT ct.colname
FROM observatory.obs_column_to_column c2c, FROM observatory.obs_column_to_column c2c,
observatory.obs_column_table ct, observatory.obs_column_table ct,
observatory.obs_table t observatory.obs_table t
WHERE c2c.reltype = ''geom_ref'' WHERE c2c.reltype = ''geom_ref''
AND ct.column_id = c2c.source_id AND ct.column_id = c2c.source_id
AND ct.table_id = t.id AND ct.table_id = t.id
AND t.tablename = %L' AND t.tablename = $1'
, target_table) INTO geoid_colname
INTO geoid_colname; USING target_table;
--RAISE NOTICE 'target_table: %, geoid_colname: %', target_table, geoid_colname; --RAISE NOTICE 'target_table: %, geoid_colname: %', target_table, geoid_colname;
@ -284,8 +284,8 @@ BEGIN
EXECUTE format( EXECUTE format(
'SELECT %I, %I::text 'SELECT %I, %I::text
FROM observatory.%I FROM observatory.%I
WHERE ST_%s($1, the_geom) WHERE ST_%s($1, %I)
', geom_colname, geoid_colname, target_table, overlap_type) ', geom_colname, geoid_colname, target_table, overlap_type, geom_colname)
USING geom; USING geom;
RETURN; RETURN;
@ -545,8 +545,7 @@ AS $$
BEGIN BEGIN
RETURN QUERY RETURN QUERY
EXECUTE EXECUTE $string$
format($string$
SELECT geoid_ct.colname::text As geoid_colname, SELECT geoid_ct.colname::text As geoid_colname,
tablename::text, tablename::text,
geom_ct.colname::text As geom_colname geom_ct.colname::text As geom_colname
@ -559,16 +558,17 @@ BEGIN
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 = $1
) )
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' AND geom_c.type ILIKE 'geometry%' AND
geom_c.id = '%s' geom_c.id = $1
ORDER BY timespan DESC ORDER BY timespan DESC
LIMIT 1 LIMIT 1
$string$, boundary_id, boundary_id); $string$
USING boundary_id;
RETURN; RETURN;
-- AND geom_t.timespan = '%s' <-- put in requested year -- AND geom_t.timespan = '%s' <-- put in requested year
-- TODO: filter by clipped vs. not so appropriate tablename are unique -- TODO: filter by clipped vs. not so appropriate tablename are unique

View File

@ -42,6 +42,12 @@ t
obs_getboundarybyid_boundary_id_mismatch_geom_id obs_getboundarybyid_boundary_id_mismatch_geom_id
t t
(1 row) (1 row)
_obs_getboundariesbygeometry_roads_around_cartodb
t
(1 row)
_obs_getboundariesbygeometry_points_around_cartodb
t
(1 row)
_obs_getboundariesbygeometry_tracts_around_cartodb _obs_getboundariesbygeometry_tracts_around_cartodb
t t
(1 row) (1 row)

View File

@ -15,10 +15,12 @@ DROP TABLE IF EXISTS observatory.obs_meta_timespan;
DROP TABLE IF EXISTS observatory.obs_column_table_tile; DROP TABLE IF EXISTS observatory.obs_column_table_tile;
DROP TABLE IF EXISTS observatory.obs_column_table_tile_simple; DROP TABLE IF EXISTS observatory.obs_column_table_tile_simple;
DROP TABLE IF EXISTS observatory.obs_fcd4e4f5610f6764973ef8c0c215b2e80bec8963; DROP TABLE IF EXISTS observatory.obs_fcd4e4f5610f6764973ef8c0c215b2e80bec8963;
DROP TABLE IF EXISTS observatory.obs_e32f8e59c7c8861ee5ee4029b3ace2af9a5c9caf;
DROP TABLE IF EXISTS observatory.obs_6c1309a64d8f3e6986061f4d1ca7b57743e75e74; DROP TABLE IF EXISTS observatory.obs_6c1309a64d8f3e6986061f4d1ca7b57743e75e74;
DROP TABLE IF EXISTS observatory.obs_0310c639744a2014bb1af82709228f05b59e7d3d; DROP TABLE IF EXISTS observatory.obs_0310c639744a2014bb1af82709228f05b59e7d3d;
DROP TABLE IF EXISTS observatory.obs_7615e8622a68bfc5fe37c69c9880edfb40250103; DROP TABLE IF EXISTS observatory.obs_7615e8622a68bfc5fe37c69c9880edfb40250103;
DROP TABLE IF EXISTS observatory.obs_d39f7fe5959891c8296490d83c22ded31c54af13; DROP TABLE IF EXISTS observatory.obs_d39f7fe5959891c8296490d83c22ded31c54af13;
DROP TABLE IF EXISTS observatory.obs_08025e1287e3af2b5de571d06562ba8d3bdb48e9;
DROP TABLE IF EXISTS observatory.obs_b393b5b88c6adda634b2071a8005b03c551b609a; DROP TABLE IF EXISTS observatory.obs_b393b5b88c6adda634b2071a8005b03c551b609a;
DROP TABLE IF EXISTS observatory.obs_78fb6c1d6ff6505225175922c2c389ce48d7632c; DROP TABLE IF EXISTS observatory.obs_78fb6c1d6ff6505225175922c2c389ce48d7632c;
DROP TABLE IF EXISTS observatory.obs_65f29658e096ca1485bf683f65fdbc9f05ec3c5d; DROP TABLE IF EXISTS observatory.obs_65f29658e096ca1485bf683f65fdbc9f05ec3c5d;

File diff suppressed because one or more lines are too long

View File

@ -115,6 +115,35 @@ SELECT cdb_observatory.OBS_GetBoundaryById(
-- _OBS_GetBoundariesByGeometry -- _OBS_GetBoundariesByGeometry
SELECT
array_agg(geom_refs) = Array[ '1104486618765', '1104486642837',
'1104991798384', '1105044325367',
'1105089330200', '1105089331758']
As _OBS_GetBoundariesByGeometry_roads_around_cartodb
FROM (
SELECT *
FROM cdb_observatory._OBS_GetBoundariesByGeometry(
-- near CartoDB's office
ST_MakeEnvelope(-74,40.69,-73.99,40.7,
4326),
'us.census.tiger.prisecroads')
ORDER BY geom_refs ASC
) As m(the_geom, geom_refs);
SELECT
array_agg(geom_refs) = Array['1102654301684', '1102654307106',
'1102654326686', '1102654351507' ]
As _OBS_GetBoundariesByGeometry_points_around_cartodb
FROM (
SELECT *
FROM cdb_observatory._OBS_GetBoundariesByGeometry(
-- near CartoDB's office
ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,
4326),
'us.census.tiger.pointlm')
ORDER BY geom_refs ASC
) As m(the_geom, geom_refs);
-- check that all census tracts intersecting with the geometry are returned -- check that all census tracts intersecting with the geometry are returned
-- order them to ensure that the same values are returned -- order them to ensure that the same values are returned
SELECT SELECT