fix divide-by-zero errors
This commit is contained in:
@@ -591,19 +591,19 @@ BEGIN
|
|||||||
' ELSE ' ||
|
' ELSE ' ||
|
||||||
' SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
' SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' THEN ST_Area(_geoms.geom) / ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' THEN ST_Area(_geoms.geom) / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0) ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
||||||
' THEN 1 ' ||
|
' THEN 1 ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' ||
|
' / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0))' ||
|
||||||
' END) / '
|
' END) / '
|
||||||
' NULLIF(SUM(' || denom_tablename || '.' || denom_colname || ' ' ||
|
' NULLIF(SUM(' || denom_tablename || '.' || denom_colname || ' ' ||
|
||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' THEN ST_Area(_geoms.geom) / ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' THEN ST_Area(_geoms.geom) / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0) ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
||||||
' THEN 1 ' ||
|
' THEN 1 ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' ||
|
' / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0))' ||
|
||||||
' END), 0) ' ||
|
' END), 0) ' ||
|
||||||
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
||||||
' END '
|
' END '
|
||||||
@@ -615,7 +615,7 @@ BEGIN
|
|||||||
' WHEN ST_GeometryType(cdb_observatory.FIRST(_geoms.geom)) = ''ST_Point'' ' ||
|
' WHEN ST_GeometryType(cdb_observatory.FIRST(_geoms.geom)) = ''ST_Point'' ' ||
|
||||||
' OR cdb_observatory.FIRST(_geoms.geom = ' || geom_tablename || '.' || geom_colname || ')' ||
|
' OR cdb_observatory.FIRST(_geoms.geom = ' || geom_tablename || '.' || geom_colname || ')' ||
|
||||||
' THEN cdb_observatory.FIRST(' || numer_tablename || '.' || numer_colname ||
|
' THEN cdb_observatory.FIRST(' || numer_tablename || '.' || numer_colname ||
|
||||||
' / (ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography)/1000000)) ' ||
|
' / (Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography), 0)/1000000)) ' ||
|
||||||
-- areaNormalized polygon interpolation
|
-- areaNormalized polygon interpolation
|
||||||
-- SUM (numer * (% OBS geom in user geom)) / area of big geom
|
-- SUM (numer * (% OBS geom in user geom)) / area of big geom
|
||||||
' ELSE ' ||
|
' ELSE ' ||
|
||||||
@@ -624,10 +624,10 @@ BEGIN
|
|||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') THEN 1 ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') THEN 1 ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) THEN ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) THEN ' ||
|
||||||
' ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' / ST_Area(_geoms.geom)' ||
|
' / Nullif(ST_Area(_geoms.geom), 0) ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(_geoms.geom))' ||
|
' / Nullif(ST_Area(_geoms.geom), 0))' ||
|
||||||
' END / (ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography) / 1000000)) ' ||
|
' END / (Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '::Geography), 0) / 1000000)) ' ||
|
||||||
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
||||||
' END '
|
' END '
|
||||||
-- median/average measures with universe
|
-- median/average measures with universe
|
||||||
@@ -647,20 +647,20 @@ BEGIN
|
|||||||
' SUM(' || numer_tablename || '.' || numer_colname ||
|
' SUM(' || numer_tablename || '.' || numer_colname ||
|
||||||
' * ' || denom_tablename || '.' || denom_colname ||
|
' * ' || denom_tablename || '.' || denom_colname ||
|
||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' THEN ST_Area(_geoms.geom) / ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' THEN ST_Area(_geoms.geom) / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0) ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
||||||
' THEN 1 ' ||
|
' THEN 1 ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' ||
|
' / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0)) ' ||
|
||||||
' END) ' ||
|
' END) ' ||
|
||||||
' / SUM(' || denom_tablename || '.' || denom_colname ||
|
' / Nullif(SUM(' || denom_tablename || '.' || denom_colname ||
|
||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' THEN ST_Area(_geoms.geom) / ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' THEN ST_Area(_geoms.geom) / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0) ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
||||||
' THEN 1 ' ||
|
' THEN 1 ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' ||
|
' / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0))' ||
|
||||||
' END) ' ||
|
' END), 0) ' ||
|
||||||
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
||||||
'END '
|
'END '
|
||||||
-- prenormalized for summable measures. point or summable only!
|
-- prenormalized for summable measures. point or summable only!
|
||||||
@@ -676,11 +676,11 @@ BEGIN
|
|||||||
-- SUM (numer * (% user geom in OBS geom))
|
-- SUM (numer * (% user geom in OBS geom))
|
||||||
' SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
' SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
||||||
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
' * CASE WHEN ST_Within(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ') ' ||
|
||||||
' THEN ST_Area(_geoms.geom) / ST_Area(' || geom_tablename || '.' || geom_colname || ') ' ||
|
' THEN ST_Area(_geoms.geom) / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0) ' ||
|
||||||
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
' WHEN ST_Within(' || geom_tablename || '.' || geom_colname || ', _geoms.geom) ' ||
|
||||||
' THEN 1 ' ||
|
' THEN 1 ' ||
|
||||||
' ELSE (ST_Area(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || ')) ' ||
|
' ELSE (ST_Area(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename || '.' || geom_colname || '))) ' ||
|
||||||
' / ST_Area(' || geom_tablename || '.' || geom_colname || '))' ||
|
' / Nullif(ST_Area(' || geom_tablename || '.' || geom_colname || '), 0))' ||
|
||||||
' END) ' ||
|
' END) ' ||
|
||||||
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
' / (COUNT(*) / COUNT(distinct ' || geom_tablename || '.' || geom_geomref_colname || ')) ' ||
|
||||||
'END '
|
'END '
|
||||||
@@ -705,8 +705,8 @@ BEGIN
|
|||||||
'.' || geom_colname || ')::TEXT'
|
'.' || geom_colname || ')::TEXT'
|
||||||
-- code below will return the intersection of the user's geom and the
|
-- code below will return the intersection of the user's geom and the
|
||||||
-- OBS geom
|
-- OBS geom
|
||||||
--'"value": "'' || ' || 'cdb_observatory.FIRST(ST_Intersection(_geoms.geom, ' || geom_tablename ||
|
--'"value": "'' || ' || 'cdb_observatory.FIRST(ST_MakeValid(ST_Intersection(_geoms.geom, ' || geom_tablename ||
|
||||||
-- '.' || geom_colname || '))::TEXT || ''"'''
|
-- '.' || geom_colname || ')))::TEXT || ''"'''
|
||||||
ELSE ''
|
ELSE ''
|
||||||
END || ')', ', ')
|
END || ')', ', ')
|
||||||
AS colspecs,
|
AS colspecs,
|
||||||
|
|||||||
Reference in New Issue
Block a user