Mercurial > gemma
diff schema/geo_functions.sql @ 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 | 1b6840093eac |
children | 69292eb68984 |
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