changeset 2838:522ed5eb449c

Work-around stability issue of ST_Centroid(geography)
author Tom Gottfried <tom@intevation.de>
date Wed, 27 Mar 2019 19:15:25 +0100
parents 61aacfd02812
children 162804509c3e
files schema/geo_functions.sql
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/schema/geo_functions.sql	Wed Mar 27 18:12:42 2019 +0100
+++ b/schema/geo_functions.sql	Wed Mar 27 19:15:25 2019 +0100
@@ -17,7 +17,12 @@
 DECLARE
   center geometry;
 BEGIN
-  SELECT CAST(ST_Centroid(g) AS geometry) INTO center;
+  -- Centroid should be calculated on geography to get accurate results
+  -- from lon/lat coordinates, but the respective PostGIS function returns
+  -- POINT(-NaN NaN) for some invalid polygons, while the calculation on
+  -- geometry seems to give reasonable approximations in this context.
+  SELECT ST_Centroid(CAST(g AS geometry)) INTO center;
+
   RETURN
     CASE WHEN ST_Y(center) > 0 THEN
     32600