Refactor and new tests

This commit is contained in:
Javier Goizueta
2016-02-18 11:28:26 +01:00
parent 89cda152bd
commit e1951e1ea9
19 changed files with 262 additions and 78 deletions
+20
View File
@@ -0,0 +1,20 @@
-- Function by Stuart Lynn for a simple interpolation of a value
-- from a polygon table over an arbitrary polygon
-- (weighted by the area proportion overlapped)
CREATE OR REPLACE
FUNCTION cdb_overlap_sum(geom geometry, target_table_name text, target_column text)
RETURNS numeric AS
$$
DECLARE
result numeric;
BEGIN
EXECUTE Format('
SELECT sum(%I*ST_Area(St_Intersection($1, a.the_geom))/ST_Area(a.the_geom))
FROM %I AS a
WHERE $1 && a.the_geom
', target_column, target_table_name)
USING geom
INTO result;
RETURN result;
END;
$$ LANGUAGE plpgsql;