adding user-selected overlap methods
This commit is contained in:
parent
2325f97684
commit
ac3574b98b
@ -248,7 +248,8 @@ $$ LANGUAGE plpgsql;
|
|||||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundariesByBBox(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundariesByBBox(
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
boundary_id text,
|
boundary_id text,
|
||||||
time_span text DEFAULT NULL)
|
time_span text DEFAULT NULL,
|
||||||
|
overlap_type text DEFAULT 'contains')
|
||||||
RETURNS TABLE(boundary geometry, geom_refs text)
|
RETURNS TABLE(boundary geometry, geom_refs text)
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -290,8 +291,8 @@ BEGIN
|
|||||||
EXECUTE format(
|
EXECUTE format(
|
||||||
'SELECT t.%s, t.%s
|
'SELECT t.%s, t.%s
|
||||||
FROM observatory.%s As t
|
FROM observatory.%s As t
|
||||||
WHERE ST_Contains($1, t.the_geom)
|
WHERE ST_%s($1, t.the_geom)
|
||||||
', geom_colname, geoid_colname, target_table)
|
', geom_colname, geoid_colname, target_table, overlap_type)
|
||||||
USING geom;
|
USING geom;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
@ -325,7 +326,8 @@ CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundariesByPointAndRadius(
|
|||||||
geom geometry(Geometry, 4326), -- point
|
geom geometry(Geometry, 4326), -- point
|
||||||
radius numeric, -- radius in meters
|
radius numeric, -- radius in meters
|
||||||
boundary_id text,
|
boundary_id text,
|
||||||
time_span text DEFAULT NULL)
|
time_span text DEFAULT NULL,
|
||||||
|
overlap_type text DEFAULT 'contains')
|
||||||
RETURNS TABLE(boundary geometry, geom_refs text)
|
RETURNS TABLE(boundary geometry, geom_refs text)
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -367,7 +369,8 @@ $$ LANGUAGE plpgsql;
|
|||||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPointsByBBox(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPointsByBBox(
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
boundary_id text,
|
boundary_id text,
|
||||||
time_span text DEFAULT NULL)
|
time_span text DEFAULT NULL,
|
||||||
|
overlap_type text DEFAULT 'contains')
|
||||||
RETURNS TABLE(boundary geometry, geom_refs text)
|
RETURNS TABLE(boundary geometry, geom_refs text)
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -379,7 +382,7 @@ 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, or 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);
|
||||||
@ -388,9 +391,6 @@ 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 '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
|
||||||
THEN
|
THEN
|
||||||
@ -405,8 +405,8 @@ BEGIN
|
|||||||
EXECUTE format(
|
EXECUTE format(
|
||||||
'SELECT ST_PointOnSurface(t.%s) As %s, t.%s
|
'SELECT ST_PointOnSurface(t.%s) As %s, t.%s
|
||||||
FROM observatory.%s As t
|
FROM observatory.%s As t
|
||||||
WHERE ST_Contains($1, t.the_geom)
|
WHERE ST_%s($1, t.the_geom)
|
||||||
', geom_colname, geom_colname, geoid_colname, target_table)
|
', geom_colname, geom_colname, geoid_colname, target_table, overlap_type)
|
||||||
USING geom;
|
USING geom;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
@ -440,7 +440,8 @@ CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPointsByPointAndRadius(
|
|||||||
geom geometry(Geometry, 4326), -- point
|
geom geometry(Geometry, 4326), -- point
|
||||||
radius numeric, -- radius in meters
|
radius numeric, -- radius in meters
|
||||||
boundary_id text,
|
boundary_id text,
|
||||||
time_span text DEFAULT NULL)
|
time_span text DEFAULT NULL,
|
||||||
|
overlap_type text DEFAULT 'contains')
|
||||||
RETURNS TABLE(boundary geometry, geom_refs text)
|
RETURNS TABLE(boundary geometry, geom_refs text)
|
||||||
AS $$
|
AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -449,7 +450,8 @@ BEGIN
|
|||||||
FROM cdb_observatory.OBS_GetPointsByBBox(
|
FROM cdb_observatory.OBS_GetPointsByBBox(
|
||||||
ST_Buffer(geom::geography, radius)::geometry,
|
ST_Buffer(geom::geography, radius)::geometry,
|
||||||
boundary_id,
|
boundary_id,
|
||||||
time_span);
|
time_span,
|
||||||
|
overlap_type);
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user