[postgis-tickets] [SCM] PostGIS branch main updated. 3.1.0rc1-337-g6f37390

git at osgeo.org git at osgeo.org
Wed Jul 14 09:46:41 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, main has been updated
       via  6f373901c677b60f7f83236fcdd8345e653bb2e4 (commit)
      from  f2cd119bba43fdffd3ace23406d145ce914096a7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6f373901c677b60f7f83236fcdd8345e653bb2e4
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Jul 14 09:46:35 2021 -0700

    Flip N/E systems to E/N and geodetic systems to Lon/Lat, while leaving Polar systems as-is, references #4949

diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h
index b871898..4fa50dd 100644
--- a/liblwgeom/liblwgeom_internal.h
+++ b/liblwgeom/liblwgeom_internal.h
@@ -68,6 +68,10 @@
 #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B))
 #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B)
 
+#define STR_EQUALS(A, B) strcmp((A), (B)) == 0
+#define STR_IEQUALS(A, B) (strcasecmp((A), (B)) == 0)
+#define STR_ISTARTS(A, B) (strncasecmp((A), (B), strlen((B))) == 0)
+
 
 /*
 * this will change to NaN when I figure out how to
@@ -209,13 +213,13 @@ void ptarray_simplify_in_place(POINTARRAY *pa, double tolerance, uint32_t minpts
 * The possible ways a pair of segments can interact. Returned by lw_segment_intersects
 */
 enum CG_SEGMENT_INTERSECTION_TYPE {
-    SEG_ERROR = -1,
-    SEG_NO_INTERSECTION = 0,
-    SEG_COLINEAR = 1,
-    SEG_CROSS_LEFT = 2,
-    SEG_CROSS_RIGHT = 3,
-    SEG_TOUCH_LEFT = 4,
-    SEG_TOUCH_RIGHT = 5
+		SEG_ERROR = -1,
+		SEG_NO_INTERSECTION = 0,
+		SEG_COLINEAR = 1,
+		SEG_CROSS_LEFT = 2,
+		SEG_CROSS_RIGHT = 3,
+		SEG_TOUCH_LEFT = 4,
+		SEG_TOUCH_RIGHT = 5
 };
 
 /*
@@ -462,14 +466,14 @@ extern uint8_t MULTITYPE[NUMTYPES];
 extern lwinterrupt_callback *_lwgeom_interrupt_callback;
 extern int _lwgeom_interrupt_requested;
 #define LW_ON_INTERRUPT(x) { \
-  if ( _lwgeom_interrupt_callback ) { \
-    (*_lwgeom_interrupt_callback)(); \
-  } \
-  if ( _lwgeom_interrupt_requested ) { \
-    _lwgeom_interrupt_requested = 0; \
-    lwnotice("liblwgeom code interrupted"); \
-    x; \
-  } \
+	if ( _lwgeom_interrupt_callback ) { \
+		(*_lwgeom_interrupt_callback)(); \
+	} \
+	if ( _lwgeom_interrupt_requested ) { \
+		_lwgeom_interrupt_requested = 0; \
+		lwnotice("liblwgeom code interrupted"); \
+		x; \
+	} \
 }
 
 int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox);
diff --git a/liblwgeom/lwgeom_transform.c b/liblwgeom/lwgeom_transform.c
index d77d3ba..3bc3799 100644
--- a/liblwgeom/lwgeom_transform.c
+++ b/liblwgeom/lwgeom_transform.c
@@ -264,40 +264,56 @@ proj_cs_get_simplecs(const PJ *pj_crs)
 static uint8_t
 proj_crs_is_swapped(const PJ *pj_crs)
 {
-	PJ *pj_cs;
-	uint8_t rv = LW_FALSE;
-
-	pj_cs = proj_cs_get_simplecs(pj_crs);
-	if (!pj_cs) {
+	int axis_count;
+	PJ *pj_cs = proj_cs_get_simplecs(pj_crs);
+	if (!pj_cs)
 		lwerror("%s: proj_cs_get_simplecs returned NULL", __func__);
-	}
-	int axis_count = proj_cs_get_axis_count(NULL, pj_cs);
-	if (axis_count > 0)
+
+	axis_count = proj_cs_get_axis_count(NULL, pj_cs);
+	if (axis_count >= 2)
 	{
-		const char *out_name, *out_abbrev, *out_direction;
-		double out_unit_conv_factor;
-		const char *out_unit_name, *out_unit_auth_name, *out_unit_code;
-		/* Read only first axis */
+		const char *out_name1, *out_abbrev1, *out_direction1;
+		const char *out_name2, *out_abbrev2, *out_direction2;
+		/* Read first axis */
 		proj_cs_get_axis_info(NULL,
-				      pj_cs,
-				      0,
-				      &out_name,
-				      &out_abbrev,
-				      &out_direction,
-				      &out_unit_conv_factor,
-				      &out_unit_name,
-				      &out_unit_auth_name,
-				      &out_unit_code);
-
-		/* Only swap Lat/Lon systems */
-		/* Use whatever ordering planar systems default to */
-		if (strcasecmp(out_abbrev, "Lat") == 0)
-			rv = LW_TRUE;
-		else
-			rv = LW_FALSE;
+			pj_cs, 0,
+			&out_name1, &out_abbrev1, &out_direction1,
+			NULL, NULL, NULL, NULL);
+		/* Read second axis */
+		proj_cs_get_axis_info(NULL,
+			pj_cs, 1,
+			&out_name2, &out_abbrev2, &out_direction2,
+			NULL, NULL, NULL, NULL);
+
+		proj_destroy(pj_cs);
+
+		/* Directions agree, this is a northing/easting CRS, so reverse it */
+		if(out_direction1 && STR_IEQUALS(out_direction1, "north") &&
+		   out_direction2 && STR_IEQUALS(out_direction2, "east") )
+		{
+			return LW_TRUE;
+		}
+
+		/* Oddball case? Both axes north / both axes south, swap */
+		if(out_direction1 && out_direction2 &&
+		   ((STR_IEQUALS(out_direction1, "north") && STR_IEQUALS(out_direction2, "north")) ||
+		    (STR_IEQUALS(out_direction1, "south") && STR_IEQUALS(out_direction2, "south"))) &&
+		   out_name1 && STR_ISTARTS(out_name1, "northing")  &&
+		   out_name2 && STR_ISTARTS(out_name2, "easting"))
+		{
+			return LW_TRUE;
+		}
+
+		/* Any lat/lon system with Lat in first axis gets swapped */
+		if (STR_ISTARTS(out_abbrev1, "Lat"))
+			return LW_TRUE;
+
+		return LW_FALSE;
 	}
+
+	/* Failed the axis count test, leave quietly */
 	proj_destroy(pj_cs);
-	return rv;
+	return LW_FALSE;
 }
 
 LWPROJ *
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index 4269354..ff61797 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1368,3 +1368,25 @@ SELECT '#4863', st_contains(geometry, st_scale(st_orientedenvelope(geometry),
  6755713.77835553,-141972.789895508 6755731.24770785))'::geometry as
  geometry) x;
 
+-- New Zealand forward -- SRID=2193;POINT(1766289 5927325)
+SELECT '#4949', 'NZ forward', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=4326;POINT(174.863597538742 -36.785298415230315)'::geometry, 2193),0.1));
+--- New Zealand inverse (opposite EPSG order) -- SRID=4326;POINT(174.863598 -36.785298)
+SELECT '#4949', 'NZ inverse', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=2193;POINT(1766289 5927325)'::geometry, 4326),0.000001));
+-- British Columbia forward (respect EPSG order) -- SRID=3005;POINT(1286630.44 561883.98)
+SELECT '#4949', 'BC forward', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=4269;POINT(-122 50)'::geometry, 3005),0.01));
+-- British Columbia inverse (respect EPSG order) -- SRID=4269;POINT(-122 50)
+SELECT '#4949', 'BC inverse', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=3005;POINT(1286630.44 561883.98)'::geometry, 4269),0.000001));
+--  North Pole LAEA Europe inverse -- SRID=4326;POINT(19.4921659 69.7902258)
+SELECT '#4949', 'North Pole LAEA inverse', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=3575;POINT(370182 -2213980)'::geometry,4326),0.0000001));
+-- Polar Stereographic forward -- SRID=3413;POINT(2218082.1 -1409150)
+SELECT '#4949', 'Arctic Stereographic forward', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=4326;POINT(12.572160  66.081084)'::geometry,3413),0.1));
+-- Antarctic Polar Stereographic -- SRID=3031;POINT(-2399498.7 3213318.5)
+SELECT '#4949', 'Antarctic Stereographic forward', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
+  'SRID=4326;POINT(-36.75 -54.25)'::geometry, 3031),0.1));
+
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index 8f6ac27..b48ecff 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -445,3 +445,10 @@ ERROR:  LWGEOM_addpoint: Invalid offset
 #4853|0
 #4844|SRID=4326;POINT(19.492 69.79)
 #4863|t
+#4949|NZ forward|SRID=2193;POINT(1766289 5927325)
+#4949|NZ inverse|SRID=4326;POINT(174.863598 -36.785298)
+#4949|BC forward|SRID=3005;POINT(1286630.44 561883.98)
+#4949|BC inverse|SRID=4269;POINT(-122 50)
+#4949|North Pole LAEA inverse|SRID=4326;POINT(19.4921659 69.7902258)
+#4949|Arctic Stereographic forward|SRID=3413;POINT(2218082.1 -1409150)
+#4949|Antarctic Stereographic forward|SRID=3031;POINT(-2399498.7 3213318.5)

-----------------------------------------------------------------------

Summary of changes:
 liblwgeom/liblwgeom_internal.h | 34 ++++++++++---------
 liblwgeom/lwgeom_transform.c   | 74 +++++++++++++++++++++++++-----------------
 regress/core/tickets.sql       | 22 +++++++++++++
 regress/core/tickets_expected  |  7 ++++
 4 files changed, 93 insertions(+), 44 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list