From c18f16ed6db6a28261a1f79510e75c5222ab7611 Mon Sep 17 00:00:00 2001 From: John Krauss Date: Tue, 17 Jan 2017 22:49:04 +0000 Subject: [PATCH] handle cases with mixed geometries in obs_getdata correctly --- src/pg/sql/41_observatory_augmentation.sql | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 2fbaaa8..1425933 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -563,7 +563,8 @@ BEGIN ' THEN 1 ' || ' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' || ' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' || - ' END), 0) ' + ' END), 0) ' || + ' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' || ' END ' -- areaNormalized WHEN LOWER(normalization) LIKE 'area%' OR (normalization IS NULL AND numer_aggregate ILIKE 'sum') @@ -584,7 +585,9 @@ BEGIN ' / ST_Area(_geoms.geom)' || ' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' || ' / ST_Area(_geoms.geom))' || - ' END / (ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography) / 1000000)) END ' + ' END / (ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography) / 1000000)) ' || + ' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' || + ' END ' -- prenormalized ELSE ' CASE ' || -- predenominated point-in-poly or user polygon is the same as OBS- polygon @@ -602,7 +605,9 @@ BEGIN ' THEN 1 ' || ' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' || ' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' || - ' END) END ' + ' END) ' || + ' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' || + 'END ' END || ':: ' || numer_type -- categorical/text