]> granicus.if.org Git - postgis/commitdiff
Better error messages for SRID mismatch.
authorDarafei Praliaskouski <me@komzpa.net>
Sun, 4 Aug 2019 11:37:34 +0000 (11:37 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Sun, 4 Aug 2019 11:37:34 +0000 (11:37 +0000)
Closes #4110
Closes https://github.com/postgis/postgis/pull/455

git-svn-id: http://svn.osgeo.org/postgis/trunk@17673 b70326c6-7e19-0410-871a-916f4a2858ee

16 files changed:
NEWS
liblwgeom/gserialized.c
liblwgeom/gserialized.h
liblwgeom/liblwgeom.h.in
liblwgeom/lwutil.c
libpgcommon/lwgeom_pg.h
postgis/geography_measurement.c
postgis/lwgeom_box.c
postgis/lwgeom_box3d.c
postgis/lwgeom_functions_analytic.c
postgis/lwgeom_functions_basic.c
postgis/lwgeom_functions_lrs.c
postgis/lwgeom_geos.c
postgis/lwgeom_spheroid.c
regress/core/ctors_expected
regress/core/split_expected

diff --git a/NEWS b/NEWS
index a532f4a386243d9cd17b70c5b933b394560a71d1..455444398101e93a9eedd84a9ee3bde61082f401 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -194,6 +194,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12
   - #4441, Make GiST penalty friendly to multi-column indexes and build single-column
            ones faster. (Darafei Praliaskouski)
   - #4403, Support for shp2pgsql ability to reproject with copy mode (-D) (Regina Obe)
+  - #4410, More descriptive error messages about SRID mismatch (Darafei Praliaskouski)
 
 * Fixes *
   - #4342, Move deprecated functions into legacy.sql file
index d746400b1bdfc10b1aed52cc272a8740b3dfac55..7492bc1ac6be676dd05ec96a00ed4d18aaf41cac 100644 (file)
@@ -398,3 +398,31 @@ gserialized_get_sortable_hash(const GSERIALIZED *g)
        else
                return gbox_get_sortable_hash(&box, gserialized_get_srid(g));
 }
+
+void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname);
+void
+gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
+{
+       int32_t srid1 = gserialized_get_srid(g1);
+       int32_t srid2 = gserialized_get_srid(g2);
+       if (srid1 != srid2)
+               lwerror("%s: Operation on mixed SRID geometries (%s, %d) != (%s, %d)",
+                       funcname,
+                       lwtype_name(gserialized1_get_type(g1)),
+                       srid1,
+                       lwtype_name(gserialized_get_type(g2)),
+                       srid2);
+}
+
+void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname);
+void
+gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
+{
+       int32_t srid1 = gserialized_get_srid(g1);
+       if (srid1 != srid2)
+               lwerror("%s: Operation on mixed SRID geometries %s %d != %d",
+                       funcname,
+                       lwtype_name(gserialized1_get_type(g1)),
+                       srid1,
+                       srid2);
+}
index df06a35d3c0951f5927df6269e2640495079d1df..5ec53f7174247fd05ae08ec77ab7c41e9aa20f26 100644 (file)
@@ -43,7 +43,7 @@ GSERIALIZED *gserialized_set_gbox(GSERIALIZED *g, GBOX *gbox);
 * Remove the bounding box from a #GSERIALIZED. Returns a freshly
 * allocated #GSERIALIZED every time.
 */
-GSERIALIZED* gserialized_drop_gbox(GSERIALIZED *g)
+GSERIALIZED *gserialized_drop_gbox(GSERIALIZED *g);
 
 /**
 * Read the box from the #GSERIALIZED or calculate it if necessary.
index bdda8313932a63f192c6b5925e944b69cb70ce60..11a93275ee75b96720cfcc3ca3f5c6b39776a56a 100644 (file)
@@ -249,9 +249,6 @@ typedef enum LWORD_T {
 */
 extern int32_t clamp_srid(int32_t srid);
 
-/* Raise an lwerror if srids do not match */
-void error_if_srid_mismatch(int32_t srid1, int32_t srid2);
-
 /**
  * Global functions for memory/logging handlers.
  */
index cbd48d1909b0ca129704411a04ba3192ef8f2678..5f63acfa8d3a2116224404f971f3d4588abd504a 100644 (file)
@@ -329,16 +329,6 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int
        return output;
 }
 
-
-void
-error_if_srid_mismatch(int32_t srid1, int32_t srid2)
-{
-       if ( srid1 != srid2 )
-       {
-               lwerror("Operation on mixed SRID geometries");
-       }
-}
-
 int32_t
 clamp_srid(int32_t srid)
 {
index b2aee8059cc64d619f0346a73c25c1612acc7688..93a52b9d7d81ff7894ef2dcfc464ee288099f6b7 100644 (file)
@@ -160,6 +160,16 @@ GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
 */
 GSERIALIZED* geography_serialize(LWGEOM *lwgeom);
 
+/**
+ * Compare SRIDs of two GSERIALIZEDs and print informative error message if they differ.
+ */
+void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname);
+
+/**
+ * Compare SRIDs of GSERIALIZEDs to reference and print informative error message if they differ.
+ */
+void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid, const char *funcname);
+
 /**
 * Pull out a gbox bounding box as fast as possible.
 * Tries to read cached box from front of serialized vardata.
index 52039bea222590a04f3b88a3bad31d372597e4a3..aa66929b2a95150372ac1056627c86dab85e41ab 100644 (file)
 #include <string.h>
 #include <stdio.h>
 
-#include "liblwgeom.h"         /* For standard geometry types. */
+#include "liblwgeom.h"                  /* For standard geometry types. */
 #include "liblwgeom_internal.h"         /* For FP comparators. */
-#include "lwgeom_pg.h"       /* For debugging macros. */
-#include "geography.h"      /* For utility functions. */
+#include "lwgeom_pg.h"                  /* For debugging macros. */
+#include "geography.h"                  /* For utility functions. */
 #include "geography_measurement_trees.h" /* For circ_tree caching */
-#include "lwgeom_transform.h" /* For SRID functions */
+#include "lwgeom_transform.h"            /* For SRID functions */
 
 #ifdef PROJ_GEODESIC
 /* round to 10 nm precision */
@@ -83,11 +83,11 @@ Datum geography_distance_knn(PG_FUNCTION_ARGS)
        g1 = PG_GETARG_GSERIALIZED_P(0);
        g2 = PG_GETARG_GSERIALIZED_P(1);
 
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
+
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
 
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
-
        /* Set to sphere if requested */
        if ( ! use_spheroid )
                s.a = s.b = s.radius;
@@ -154,7 +154,7 @@ Datum geography_distance_uncached(PG_FUNCTION_ARGS)
        if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
                use_spheroid = PG_GETARG_BOOL(3);
 
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
 
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
@@ -218,8 +218,7 @@ Datum geography_distance(PG_FUNCTION_ARGS)
        if (PG_NARGS() > 2)
                use_spheroid = PG_GETARG_BOOL(2);
 
-
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
 
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
@@ -283,6 +282,8 @@ Datum geography_dwithin(PG_FUNCTION_ARGS)
        double distance;
        int dwithin = LW_FALSE;
 
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
+
        /* Read our tolerance value. */
        if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
                tolerance = PG_GETARG_FLOAT8(2);
@@ -291,8 +292,6 @@ Datum geography_dwithin(PG_FUNCTION_ARGS)
        if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
                use_spheroid = PG_GETARG_BOOL(3);
 
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
-
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
 
@@ -349,7 +348,9 @@ Datum geography_distance_tree(PG_FUNCTION_ARGS)
        g1 = PG_GETARG_GSERIALIZED_P(0);
        g2 = PG_GETARG_GSERIALIZED_P(1);
 
-       /* Return FALSE on empty arguments. */
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
+
+       /* Return zero on empty arguments. */
        if ( gserialized_is_empty(g1) || gserialized_is_empty(g2) )
        {
                PG_FREE_IF_COPY(g1, 0);
@@ -365,8 +366,6 @@ Datum geography_distance_tree(PG_FUNCTION_ARGS)
        if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
                use_spheroid = PG_GETARG_BOOL(3);
 
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
-
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
 
@@ -404,6 +403,7 @@ Datum geography_dwithin_uncached(PG_FUNCTION_ARGS)
        /* Get our geometry objects loaded into memory. */
        g1 = PG_GETARG_GSERIALIZED_P(0);
        g2 = PG_GETARG_GSERIALIZED_P(1);
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
 
        /* Read our tolerance value. */
        if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
@@ -413,8 +413,6 @@ Datum geography_dwithin_uncached(PG_FUNCTION_ARGS)
        if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
                use_spheroid = PG_GETARG_BOOL(3);
 
-       error_if_srid_mismatch(gserialized_get_srid(g1), gserialized_get_srid(g2));
-
        /* Initialize spheroid */
        spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
 
@@ -733,13 +731,12 @@ Datum geography_covers(PG_FUNCTION_ARGS)
        /* Get our geometry objects loaded into memory. */
        g1 = PG_GETARG_GSERIALIZED_P(0);
        g2 = PG_GETARG_GSERIALIZED_P(1);
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
 
        /* Construct our working geometries */
        lwgeom1 = lwgeom_from_gserialized(g1);
        lwgeom2 = lwgeom_from_gserialized(g2);
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
-
        /* EMPTY never intersects with another geometry */
        if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
        {
@@ -775,13 +772,12 @@ Datum geography_coveredby(PG_FUNCTION_ARGS)
        /* Pick them up in reverse order to covers */
        g1 = PG_GETARG_GSERIALIZED_P(1);
        g2 = PG_GETARG_GSERIALIZED_P(0);
+       gserialized_error_if_srid_mismatch(g1, g2, __func__);
 
        /* Construct our working geometries */
        lwgeom1 = lwgeom_from_gserialized(g1);
        lwgeom2 = lwgeom_from_gserialized(g2);
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
-
        /* EMPTY never intersects with another geometry */
        if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
        {
index 2de2280bc7e8df39ce78e538317e4ca6c154186f..4368728f9bc38bc9a59efb949f11def5468f4e6d 100644 (file)
@@ -537,6 +537,7 @@ Datum BOX2D_construct(PG_FUNCTION_ARGS)
        GBOX *result;
        LWPOINT *minpoint, *maxpoint;
        double min, max, tmp;
+       gserialized_error_if_srid_mismatch(pgmin, pgmax, __func__);
 
        minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
        maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
@@ -552,8 +553,6 @@ Datum BOX2D_construct(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
-
        result = gbox_new(lwflags(0, 0, 0));
 
        /* Process X min/max */
index 77e69aa6e727d0fd4e9befb1cf58029229e9ac0d..9a34500ee2aed746c9df35d0e9f73d41d5587084 100644 (file)
@@ -570,7 +570,7 @@ Datum BOX3D_construct(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
+       gserialized_error_if_srid_mismatch(min, max, __func__);
 
        getPoint3dz_p(((LWPOINT *)minpoint)->point, 0, &minp);
        getPoint3dz_p(((LWPOINT *)maxpoint)->point, 0, &maxp);
index 1c7a6fe4045e4034b2a01b0418c5399033f1beac..3680e502162c9a7ddb2fb59a75e7c7a9a825af07 100644 (file)
@@ -33,7 +33,6 @@
 #include "lwgeom_rtree.h"
 #include "lwgeom_functions_analytic.h"
 
-
 #include "access/htup_details.h"
 
 /* Prototypes */
@@ -479,7 +478,7 @@ Datum ST_LineCrossingDirection(PG_FUNCTION_ARGS)
        GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
        GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
 
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        type1 = gserialized_get_type(geom1);
        type2 = gserialized_get_type(geom2);
index b067feec9cc2d646d73bc4dd02d4d432493fff99..61cde6228aa2b0afb87bd6b158b0bf49459547d0 100644 (file)
@@ -604,8 +604,7 @@ Datum LWGEOM_closestpoint(PG_FUNCTION_ARGS)
        LWGEOM *point;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        point = lwgeom_closest_point(lwgeom1, lwgeom2);
 
@@ -634,8 +633,7 @@ Datum LWGEOM_shortestline2d(PG_FUNCTION_ARGS)
        LWGEOM *theline;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        theline = lwgeom_closest_line(lwgeom1, lwgeom2);
 
@@ -664,8 +662,7 @@ Datum LWGEOM_longestline2d(PG_FUNCTION_ARGS)
        LWGEOM *theline;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        theline = lwgeom_furthest_line(lwgeom1, lwgeom2);
 
@@ -692,8 +689,7 @@ Datum ST_Distance(PG_FUNCTION_ARGS)
        GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        mindist = lwgeom_mindistance2d(lwgeom1, lwgeom2);
 
@@ -731,7 +727,7 @@ Datum LWGEOM_dwithin(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        mindist = lwgeom_mindistance2d_tolerance(lwgeom1, lwgeom2, tolerance);
 
@@ -763,7 +759,7 @@ Datum LWGEOM_dfullywithin(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        maxdist = lwgeom_maxdistance2d_tolerance(lwgeom1, lwgeom2, tolerance);
 
@@ -788,8 +784,7 @@ Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS)
        GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        maxdist = lwgeom_maxdistance2d(lwgeom1, lwgeom2);
 
@@ -816,8 +811,7 @@ Datum LWGEOM_closestpoint3d(PG_FUNCTION_ARGS)
        LWGEOM *point;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        point = lwgeom_closest_point_3d(lwgeom1, lwgeom2);
        // point = lw_dist3d_distancepoint(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
@@ -848,8 +842,7 @@ Datum LWGEOM_shortestline3d(PG_FUNCTION_ARGS)
        LWGEOM *theline;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        theline = lwgeom_closest_line_3d(lwgeom1, lwgeom2);
        // theline = lw_dist3d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
@@ -880,8 +873,7 @@ Datum LWGEOM_longestline3d(PG_FUNCTION_ARGS)
        LWGEOM *theline;
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        theline = lwgeom_furthest_line_3d(lwgeom1, lwgeom2);
        // theline = lw_dist3d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MAX);
@@ -910,8 +902,7 @@ Datum ST_3DDistance(PG_FUNCTION_ARGS)
        GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        mindist = lwgeom_mindistance3d(lwgeom1, lwgeom2);
 
@@ -934,8 +925,7 @@ Datum ST_3DIntersects(PG_FUNCTION_ARGS)
        GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
-
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        mindist = lwgeom_mindistance3d_tolerance(lwgeom1, lwgeom2, 0.0);
 
@@ -968,7 +958,7 @@ Datum LWGEOM_dwithin3d(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        mindist = lwgeom_mindistance3d_tolerance(lwgeom1, lwgeom2, tolerance);
 
@@ -1001,7 +991,7 @@ Datum LWGEOM_dfullywithin3d(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
        maxdist = lwgeom_maxdistance3d_tolerance(lwgeom1, lwgeom2, tolerance);
 
        PG_FREE_IF_COPY(geom1, 0);
@@ -1026,7 +1016,7 @@ Datum LWGEOM_maxdistance3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        maxdist = lwgeom_maxdistance3d(lwgeom1, lwgeom2);
 
@@ -1160,6 +1150,7 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
 
        gser1 = PG_GETARG_GSERIALIZED_P(0);
        gser2 = PG_GETARG_GSERIALIZED_P(1);
+       gserialized_error_if_srid_mismatch(gser1, gser2, __func__);
 
        POSTGIS_DEBUGF(3,
                       "LWGEOM_collect(%s, %s): call",
@@ -1174,7 +1165,6 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        }
 
        srid = gserialized_get_srid(gser1);
-       error_if_srid_mismatch(srid, gserialized_get_srid(gser2));
 
        lwgeoms[0] = lwgeom_from_gserialized(gser1);
        lwgeoms[1] = lwgeom_from_gserialized(gser2);
@@ -1286,22 +1276,18 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
 
                        /* COMPUTE_BBOX WHEN_SIMPLE */
                        if (lwgeoms[count]->bbox)
-                       {
                                box = gbox_copy(lwgeoms[count]->bbox);
-                       }
                }
                else
                {
                        /* Check SRID homogeneity */
-                       error_if_srid_mismatch(lwgeoms[count]->srid, srid);
+                       gserialized_error_if_srid_mismatch_reference(geom, srid, __func__);
 
                        /* COMPUTE_BBOX WHEN_SIMPLE */
                        if (box)
                        {
                                if (lwgeoms[count]->bbox)
-                               {
                                        gbox_merge(lwgeoms[count]->bbox, box);
-                               }
                                else
                                {
                                        pfree(box);
@@ -1460,9 +1446,7 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
                        /* TODO: also get ZMflags */
                }
                else
-               {
-                       error_if_srid_mismatch(geoms[ngeoms - 1]->srid, srid);
-               }
+                       gserialized_error_if_srid_mismatch_reference(geom, srid, __func__);
 
                POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
        }
@@ -1510,7 +1494,7 @@ Datum LWGEOM_makeline(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(gserialized_get_srid(pglwg1), gserialized_get_srid(pglwg2));
+       gserialized_error_if_srid_mismatch(pglwg1, pglwg2, __func__);
 
        lwgeoms[0] = lwgeom_from_gserialized(pglwg1);
        lwgeoms[1] = lwgeom_from_gserialized(pglwg2);
@@ -2578,11 +2562,9 @@ Datum optimistic_overlap(PG_FUNCTION_ARGS)
        double dist = PG_GETARG_FLOAT8(2);
        GBOX g1_bvol;
        double calc_dist;
-
        LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
        LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
-
-       error_if_srid_mismatch(geom1->srid, geom2->srid);
+       gserialized_error_if_srid_mismatch(pg_geom1, pg_geom2, __func__);
 
        if (geom1->type != POLYGONTYPE)
        {
index d6dac837ea45857b7e31817f827391754c4f75b4..a97fa0873f560c833f6babe6dc2dd8a63d50ac4c 100644 (file)
@@ -199,7 +199,7 @@ Datum ST_InterpolatePoint(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(gserialized_get_srid(gser_line), gserialized_get_srid(gser_point));
+       gserialized_error_if_srid_mismatch(gser_line, gser_point, __func__);
 
        if ( ! gserialized_has_m(gser_line) )
        {
@@ -237,7 +237,7 @@ Datum LWGEOM_line_locate_point(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        lwline = lwgeom_as_lwline(lwgeom_from_gserialized(geom1));
        lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom2));
index fa4a781f39b72abfbfafe4d3711ddb291b0450f1..f91f7054daa9976db84c97619cedbf118bcd8d36 100644 (file)
@@ -44,7 +44,6 @@
 #include "liblwgeom.h"
 #include "lwgeom_rtree.h"
 #include "lwgeom_geos_prepared.h"
-
 #include "float.h" /* for DBL_DIG */
 
 
@@ -420,9 +419,7 @@ Datum pgis_union_geometry_array(PG_FUNCTION_ARGS)
 
                /* Check for SRID mismatch in array elements */
                if ( gotsrid )
-               {
-                       error_if_srid_mismatch(srid, gserialized_get_srid(gser_in));
-               }
+                       gserialized_error_if_srid_mismatch_reference(gser_in, srid, __func__);
                else
                {
                        /* Initialize SRID/dimensions info */
@@ -570,7 +567,8 @@ Datum pgis_geometry_union_transfn(PG_FUNCTION_ARGS)
                        if (state->srid != gserialized_get_srid(gser_in))
                                for (curgeom = 0; curgeom < state->ngeoms; curgeom++)
                                        GEOSGeom_destroy(state->geoms[curgeom]);
-                       error_if_srid_mismatch(state->srid, gserialized_get_srid(gser_in));
+
+                       gserialized_error_if_srid_mismatch_reference(gser_in, state->srid, __func__);
                }
 
                if (!gserialized_is_empty(gser_in))
@@ -1681,8 +1679,7 @@ Datum overlaps(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Overlaps(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -1737,8 +1734,7 @@ Datum contains(PG_FUNCTION_ARGS)
        GEOSGeometry *g1, *g2;
        GBOX box1, box2;
        PrepGeomCache *prep_cache;
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Contains(Empty) == FALSE */
        if (gserialized_is_empty(geom1) || gserialized_is_empty(geom2))
@@ -1877,8 +1873,7 @@ Datum containsproperly(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.ContainsProperly(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -1952,7 +1947,7 @@ Datum covers(PG_FUNCTION_ARGS)
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
                PG_RETURN_BOOL(false);
 
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /*
         * short-circuit 1: if geom2 bounding box is not completely inside
@@ -2082,8 +2077,7 @@ Datum coveredby(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.CoveredBy(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -2196,8 +2190,7 @@ Datum crosses(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Crosses(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -2253,8 +2246,7 @@ Datum ST_Intersects(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Intersects(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -2379,8 +2371,7 @@ Datum touches(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Touches(Empty) == FALSE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -2437,8 +2428,7 @@ Datum disjoint(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* A.Disjoint(Empty) == TRUE */
        if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
@@ -2496,11 +2486,10 @@ Datum relate_pattern(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* TODO handle empty */
 
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
-
        initGEOS(lwpgnotice, lwgeom_geos_error);
 
        g1 = POSTGIS2GEOS(geom1);
@@ -2550,19 +2539,13 @@ Datum relate_full(PG_FUNCTION_ARGS)
        text *result;
        int bnr = GEOSRELATE_BNR_OGC;
 
-       POSTGIS_DEBUG(2, "in relate_full()");
-
        /* TODO handle empty */
-
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        if ( PG_NARGS() > 2 )
-       {
                bnr = PG_GETARG_INT32(2);
-       }
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        initGEOS(lwpgnotice, lwgeom_geos_error);
 
@@ -2609,8 +2592,7 @@ Datum ST_Equals(PG_FUNCTION_ARGS)
 
        geom1 = PG_GETARG_GSERIALIZED_P(0);
        geom2 = PG_GETARG_GSERIALIZED_P(1);
-
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* Empty == Empty */
        if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
@@ -2815,11 +2797,8 @@ LWGEOM** ARRAY2LWGEOM(ArrayType* array, uint32_t nelems,  int* is3d, int* srid)
                    gotsrid = true;
                    *srid = gserialized_get_srid(geom);
            }
-           else if (*srid != gserialized_get_srid(geom))
-           {
-                   error_if_srid_mismatch(*srid, gserialized_get_srid(geom));
-                   return NULL;
-           }
+           else
+                   gserialized_error_if_srid_mismatch_reference(geom, *srid, __func__);
 
            i++;
     }
@@ -2869,11 +2848,10 @@ GEOSGeometry** ARRAY2GEOS(ArrayType* array, uint32_t nelems, int* is3d, int* sri
                else if (*srid != gserialized_get_srid(geom))
                {
             uint32_t j;
-            error_if_srid_mismatch(*srid, gserialized_get_srid(geom));
-
             for (j = 0; j <= i; j++) {
                                GEOSGeom_destroy(geos_geoms[j]);
                        }
+                       gserialized_error_if_srid_mismatch_reference(geom, *srid, __func__);
                        return NULL;
                }
 
@@ -3259,12 +3237,11 @@ Datum ST_Split(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom_in, *lwblade_in, *lwgeom_out;
 
        in = PG_GETARG_GSERIALIZED_P(0);
-       lwgeom_in = lwgeom_from_gserialized(in);
-
        blade_in = PG_GETARG_GSERIALIZED_P(1);
-       lwblade_in = lwgeom_from_gserialized(blade_in);
+       gserialized_error_if_srid_mismatch(in, blade_in, __func__);
 
-       error_if_srid_mismatch(lwgeom_in->srid, lwblade_in->srid);
+       lwgeom_in = lwgeom_from_gserialized(in);
+       lwblade_in = lwgeom_from_gserialized(blade_in);
 
        lwgeom_out = lwgeom_split(lwgeom_in, lwblade_in);
        lwgeom_free(lwgeom_in);
index 8acf34ef78f2b5101c05251801a64b33e5aa1245..fd96bc4957571a08de92c1f54b2be13e93d9bcc6 100644 (file)
@@ -489,12 +489,11 @@ Datum geometry_distance_spheroid(PG_FUNCTION_ARGS)
        bool use_spheroid = PG_GETARG_BOOL(3);
        LWGEOM *lwgeom1, *lwgeom2;
        double distance;
+       gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
 
        /* Calculate some other parameters on the spheroid */
        spheroid_init(sphere, sphere->a, sphere->b);
 
-       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
-
        /* Catch sphere special case and re-jig spheroid appropriately */
        if ( ! use_spheroid )
        {
index 26b0c2956cd27c8b5120db183630457a6e0f8fa0..a459f433a0380a45d56c8bddb0e07f1c3928593c 100644 (file)
@@ -1,11 +1,11 @@
 32749
-ERROR:  Operation on mixed SRID geometries
+ERROR:  LWGEOM_collect: Operation on mixed SRID geometries (Point, 32749) != (Point, 32740)
 SRID=3;LINESTRING(0 0,1 1)
-ERROR:  Operation on mixed SRID geometries
+ERROR:  LWGEOM_makeline: Operation on mixed SRID geometries (Point, 0) != (Point, 3)
 ST_MakeLine1|LINESTRING(0 0,1 1,10 0)
 ST_MakeLine_agg1|LINESTRING(0 0,1 1,10 0,20 20,40 4,40 4,40 5,40 5,40 6,40 6,40 7,40 8)
 ST_MakeLine_agg2|LINESTRING(0 0,1 0,1 0)
 BOX(0 0,1 1)
-ERROR:  Operation on mixed SRID geometries
+ERROR:  BOX2D_construct: Operation on mixed SRID geometries (Point, 0) != (Point, 3)
 BOX3D(0 0 0,1 1 0)
-ERROR:  Operation on mixed SRID geometries
+ERROR:  BOX3D_construct: Operation on mixed SRID geometries (Point, 0) != (Point, 3)
index 64735cf0ce91662fe1a5ef48cbf0ac9fec2cef53..a73ba155d4a90202d97e970dc9dbbf117e60e0fa 100644 (file)
@@ -1,9 +1,9 @@
-ERROR:  Operation on mixed SRID geometries
+ERROR:  ST_Split: Operation on mixed SRID geometries (LineString, 10) != (Point, 5)
 1|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,5 0),LINESTRING(5 0,10 0))
 1.1|SRID=10;GEOMETRYCOLLECTION(LINESTRING(10 0,5 0),LINESTRING(5 0,0 0))
 2|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))
 3|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))
-ERROR:  Operation on mixed SRID geometries
+ERROR:  ST_Split: Operation on mixed SRID geometries (LineString, 10) != (LineString, 5)
 4|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))
 5|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))
 6|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,5 0),LINESTRING(5 0,10 0))