changeset 2833:1b6840093eac

Prevent calculation of wrong UTM zones Using geography as input data type will ensure only lon/lat coordinates are fed into the calculation.
author Tom Gottfried <tom@intevation.de>
date Wed, 27 Mar 2019 15:39:52 +0100
parents b5555005f51e
children f91ee5d2c58a
files pkg/imports/dma.go pkg/imports/fd.go pkg/imports/sr.go pkg/imports/wa.go pkg/imports/wx.go schema/geo_functions.sql
diffstat 6 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/dma.go	Wed Mar 27 15:37:36 2019 +0100
+++ b/pkg/imports/dma.go	Wed Mar 27 15:39:52 2019 +0100
@@ -77,8 +77,8 @@
 const (
 	deleteDistanceMarksSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
@@ -89,8 +89,8 @@
 `
 	insertDistanceMarksSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
--- a/pkg/imports/fd.go	Wed Mar 27 15:37:36 2019 +0100
+++ b/pkg/imports/fd.go	Wed Mar 27 15:39:52 2019 +0100
@@ -139,8 +139,8 @@
 
 	deleteFairwayDimensionSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
@@ -155,8 +155,8 @@
 	// avoid errors due to reprojection.
 	insertFairwayDimensionSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
--- a/pkg/imports/sr.go	Wed Mar 27 15:37:36 2019 +0100
+++ b/pkg/imports/sr.go	Wed Mar 27 15:39:52 2019 +0100
@@ -124,8 +124,8 @@
   id,
   ST_X(ST_Centroid(area::geometry)),
   ST_Y(ST_Centroid(area::geometry)),
-  best_utm(area::geometry),
-  ST_AsBinary(ST_Transform(area::geometry, best_utm(area::geometry)))
+  best_utm(area),
+  ST_AsBinary(ST_Transform(area::geometry, best_utm(area)))
 `
 
 	reprojectPointsSQL = `
--- a/pkg/imports/wa.go	Wed Mar 27 15:37:36 2019 +0100
+++ b/pkg/imports/wa.go	Wed Mar 27 15:39:52 2019 +0100
@@ -81,8 +81,8 @@
 const (
 	deleteWaterwayAreaSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
@@ -93,8 +93,8 @@
 `
 	insertWaterwayAreaSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
--- a/pkg/imports/wx.go	Wed Mar 27 15:37:36 2019 +0100
+++ b/pkg/imports/wx.go	Wed Mar 27 15:39:52 2019 +0100
@@ -80,8 +80,8 @@
 const (
 	deleteWaterwayAxisSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
@@ -100,8 +100,8 @@
 
 	insertWaterwayAxisSQL = `
 WITH resp AS (
-  SELECT best_utm(area::geometry) AS t,
-         ST_Transform(area::geometry, best_utm(area::geometry)) AS a
+  SELECT best_utm(area) AS t,
+         ST_Transform(area::geometry, best_utm(area)) AS a
   FROM users.responsibility_areas
   WHERE country = users.current_user_country()
 )
--- a/schema/geo_functions.sql	Wed Mar 27 15:37:36 2019 +0100
+++ b/schema/geo_functions.sql	Wed Mar 27 15:39:52 2019 +0100
@@ -4,19 +4,20 @@
 -- SPDX-License-Identifier: AGPL-3.0-or-later
 -- License-Filename: LICENSES/AGPL-3.0.txt
 
--- Copyright (C) 2018 by via donau
+-- Copyright (C) 2018, 2019 by via donau
 --   – Österreichische Wasserstraßen-Gesellschaft mbH
 -- Software engineering by Intevation GmbH
 
 -- Author(s):
 --  * 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;
+  SELECT CAST(ST_Centroid(g) AS geometry) INTO center;
   RETURN
     CASE WHEN ST_Y(center) > 0 THEN
     32600