changeset 3596:eeeb7bf14217

reverted best_utm() back to geography only version.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 04 Jun 2019 16:50:17 +0200
parents d4ff8ea19f2c
children d1bbfb9635ca
files pkg/imports/sr.go schema/geo_functions.sql
diffstat 2 files changed, 8 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/sr.go	Tue Jun 04 14:44:02 2019 +0200
+++ b/pkg/imports/sr.go	Tue Jun 04 16:50:17 2019 +0200
@@ -179,8 +179,8 @@
 SELECT ST_AsBinary(
   ST_Transform(
     ST_GeomFromWKB($1, $2::integer),
-	best_utm(ST_GeomFromWKB($1, $2::integer)))),
-	best_utm(ST_GeomFromWKB($1, $2::integer)
+	best_utm(CAST(ST_GeomFromWKB($1, $2::integer) AS geography))),
+	best_utm(CAST(ST_GeomFromWKB($1, $2::integer) AS geography))
 `
 )
 
--- a/schema/geo_functions.sql	Tue Jun 04 14:44:02 2019 +0200
+++ b/schema/geo_functions.sql	Tue Jun 04 16:50:17 2019 +0200
@@ -12,12 +12,16 @@
 --  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
 --  * Tom Gottfried <tom@intevation.de>
 
-CREATE OR REPLACE FUNCTION best_utm(g geometry) RETURNS integer AS
+CREATE OR REPLACE FUNCTION best_utm(g geography) RETURNS integer AS
 $$
 DECLARE
   center geometry;
 BEGIN
-  SELECT ST_Centroid(g) 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
@@ -29,17 +33,3 @@
 $$
 LANGUAGE plpgsql
 IMMUTABLE;
-
-CREATE OR REPLACE FUNCTION best_utm(g geography) RETURNS integer AS
-$$
-BEGIN
-  -- 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.
-  RETURN best_utm(CAST(g as geometry));
-END;
-$$
-LANGUAGE plpgsql
-IMMUTABLE;
-