changeset 3589:033366f94abf

Added a geometry version of best_utm() for convenience.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 04 Jun 2019 12:29:20 +0200
parents cffa99aa523c
children 309084558808
files schema/geo_functions.sql
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/schema/geo_functions.sql	Tue Jun 04 12:12:30 2019 +0200
+++ b/schema/geo_functions.sql	Tue Jun 04 12:29:20 2019 +0200
@@ -12,16 +12,12 @@
 --  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
 --  * Tom Gottfried <tom@intevation.de>
 
-CREATE OR REPLACE FUNCTION best_utm(g geography) RETURNS integer AS
+CREATE OR REPLACE FUNCTION best_utm(g geometry) RETURNS integer AS
 $$
 DECLARE
   center geometry;
 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.
-  SELECT ST_Centroid(CAST(g AS geometry)) INTO center;
+  SELECT ST_Centroid(g) INTO center;
 
   RETURN
     CASE WHEN ST_Y(center) > 0 THEN
@@ -33,3 +29,17 @@
 $$
 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;
+