# HG changeset patch # User Sascha L. Teichmann # Date 1559659817 -7200 # Node ID eeeb7bf142170ce85dc30f7e44f23b8418d94f8b # Parent d4ff8ea19f2c125335d9f45f9b6bee1fde58e207 reverted best_utm() back to geography only version. diff -r d4ff8ea19f2c -r eeeb7bf14217 pkg/imports/sr.go --- 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)) ` ) diff -r d4ff8ea19f2c -r eeeb7bf14217 schema/geo_functions.sql --- 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 -- * Tom Gottfried -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; -