]> granicus.if.org Git - postgis/commitdiff
Harmonize SRID mismatch handling to use same function
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 22 Jul 2015 13:37:07 +0000 (13:37 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 22 Jul 2015 13:37:07 +0000 (13:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13824 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_btree.c
postgis/lwgeom_functions_basic.c
postgis/lwgeom_functions_lrs.c
postgis/lwgeom_geos.c

index 3553ea5eaea9065ce7655c46143157700e969eaa..b891ebe8889d36756219b4b4928a09f53076a0f3 100644 (file)
@@ -38,9 +38,6 @@ Datum lwgeom_ge(PG_FUNCTION_ARGS);
 Datum lwgeom_gt(PG_FUNCTION_ARGS);
 Datum lwgeom_cmp(PG_FUNCTION_ARGS);
 
-
-#define BTREE_SRID_MISMATCH_SEVERITY ERROR
-
 PG_FUNCTION_INFO_V1(lwgeom_lt);
 Datum lwgeom_lt(PG_FUNCTION_ARGS)
 {
@@ -51,14 +48,7 @@ Datum lwgeom_lt(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_lt called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        POSTGIS_DEBUG(3, "lwgeom_lt passed getSRID test");
 
@@ -107,14 +97,7 @@ Datum lwgeom_le(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_le called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        gserialized_get_gbox_p(geom1, &box1);
        gserialized_get_gbox_p(geom2, &box2);
@@ -173,14 +156,7 @@ Datum lwgeom_eq(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_eq called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        gbox_init(&box1);
        gbox_init(&box2);
@@ -217,14 +193,7 @@ Datum lwgeom_ge(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_ge called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        gserialized_get_gbox_p(geom1, &box1);
        gserialized_get_gbox_p(geom2, &box2);
@@ -281,14 +250,7 @@ Datum lwgeom_gt(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_gt called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        gserialized_get_gbox_p(geom1, &box1);
        gserialized_get_gbox_p(geom2, &box2);
@@ -341,14 +303,7 @@ Datum lwgeom_cmp(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "lwgeom_cmp called");
 
-       if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
-       {
-               elog(BTREE_SRID_MISMATCH_SEVERITY,
-                    "Operation on two GEOMETRIES with different SRIDs\n");
-               PG_FREE_IF_COPY(geom1, 0);
-               PG_FREE_IF_COPY(geom2, 1);
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        gserialized_get_gbox_p(geom1, &box1);
        gserialized_get_gbox_p(geom2, &box2);
index 4c2e585e08d17a787ef976b4426a40f13c392565..9ab8f41c6271e0ee28ce4ef626b12d9e7fcee0ce 100644 (file)
@@ -590,11 +590,7 @@ Datum LWGEOM_closestpoint(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        point = lwgeom_closest_point(lwgeom1, lwgeom2);
 
@@ -624,11 +620,7 @@ Datum LWGEOM_shortestline2d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        theline = lwgeom_closest_line(lwgeom1, lwgeom2);
        
@@ -658,11 +650,7 @@ Datum LWGEOM_longestline2d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        theline = lwgeom_furthest_line(lwgeom1, lwgeom2);
        
@@ -690,11 +678,7 @@ Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        mindist = lwgeom_mindistance2d(lwgeom1, lwgeom2);
 
@@ -732,11 +716,7 @@ Datum LWGEOM_dwithin(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        mindist = lwgeom_mindistance2d_tolerance(lwgeom1,lwgeom2,tolerance);
 
@@ -768,11 +748,7 @@ Datum LWGEOM_dfullywithin(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
        
        maxdist = lwgeom_maxdistance2d_tolerance(lwgeom1, lwgeom2, tolerance);
 
@@ -798,11 +774,7 @@ Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        maxdist = lwgeom_maxdistance2d(lwgeom1, lwgeom2);
 
@@ -830,11 +802,7 @@ Datum LWGEOM_closestpoint3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        point = lwgeom_closest_point_3d(lwgeom1, lwgeom2);
        // point = lw_dist3d_distancepoint(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
@@ -866,11 +834,7 @@ Datum LWGEOM_shortestline3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        theline = lwgeom_closest_line_3d(lwgeom1, lwgeom2);
        // theline = lw_dist3d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
@@ -902,11 +866,7 @@ Datum LWGEOM_longestline3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        theline = lwgeom_furthest_line_3d(lwgeom1, lwgeom2);
        // theline = lw_dist3d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MAX);
@@ -936,11 +896,7 @@ Datum LWGEOM_mindistance3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        mindist = lwgeom_mindistance3d(lwgeom1, lwgeom2);
 
@@ -975,11 +931,7 @@ Datum LWGEOM_dwithin3d(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        mindist = lwgeom_mindistance3d_tolerance(lwgeom1,lwgeom2,tolerance);
 
@@ -1012,11 +964,7 @@ Datum LWGEOM_dfullywithin3d(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
        maxdist = lwgeom_maxdistance3d_tolerance(lwgeom1, lwgeom2, tolerance);
 
        PG_FREE_IF_COPY(geom1, 0);
@@ -1041,11 +989,7 @@ Datum LWGEOM_maxdistance3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if (lwgeom1->srid != lwgeom2->srid)
-       {
-               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
        maxdist = lwgeom_maxdistance3d(lwgeom1, lwgeom2);
 
@@ -1281,11 +1225,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
                else
                {
                        /* Check SRID homogeneity */
-                       if ( lwgeoms[count]->srid != srid )
-                       {
-                               elog(ERROR, "Operation on mixed SRID geometries");
-                               PG_RETURN_NULL();
-                       }
+                       error_if_srid_mismatch(lwgeoms[count]->srid, srid);
 
                        /* COMPUTE_BBOX WHEN_SIMPLE */
                        if ( box )
@@ -1468,11 +1408,7 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
                }
                else
                {
-                       if ( geoms[ngeoms-1]->srid != srid )
-                       {
-                               elog(ERROR, "Operation on mixed SRID geometries");
-                               PG_RETURN_NULL();
-                       }
+                       error_if_srid_mismatch(geoms[ngeoms-1]->srid, srid);
                }
 
                POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
@@ -2193,7 +2129,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
        LWLINE *line, *linecopy;
        int where = -1;
 
-       POSTGIS_DEBUG(2, "LWGEOM_addpoint called.");
+       POSTGIS_DEBUGF(2, "%s called.", __func__);
 
        pglwg1 = PG_GETARG_GSERIALIZED_P(0);
        pglwg2 = PG_GETARG_GSERIALIZED_P(1);
@@ -2465,11 +2401,7 @@ Datum optimistic_overlap(PG_FUNCTION_ARGS)
        LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
        LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
 
-       if (geom1->srid != geom2->srid)
-       {
-               elog(ERROR,"optimistic_overlap:Operation on two GEOMETRIES with different SRIDs\\n");
-               PG_RETURN_NULL();
-       }
+       error_if_srid_mismatch(geom1->srid, geom2->srid);
 
        if (geom1->type != POLYGONTYPE)
        {
index 55ed1320901454fdf161131d4ac5aa2634b581aa..4e038f5e88e83d8157a336118586807a18808aef 100644 (file)
@@ -185,11 +185,9 @@ Datum ST_InterpolatePoint(PG_FUNCTION_ARGS)
                elog(ERROR,"ST_InterpolatePoint: 2st argument isn't a point");
                PG_RETURN_NULL();
        }
-       if ( gserialized_get_srid(gser_line) != gserialized_get_srid(gser_point) )
-       {
-               elog(ERROR, "Operation on two geometries with different SRIDs");
-               PG_RETURN_NULL();
-       }
+
+       error_if_srid_mismatch(gserialized_get_srid(gser_line), gserialized_get_srid(gser_point));
+
        if ( ! gserialized_has_m(gser_line) )
        {
                elog(ERROR,"ST_InterpolatePoint only accepts geometries that have an M dimension");
@@ -225,11 +223,8 @@ Datum LWGEOM_line_locate_point(PG_FUNCTION_ARGS)
                elog(ERROR,"line_locate_point: 2st arg isnt a point");
                PG_RETURN_NULL();
        }
-       if ( gserialized_get_srid(geom1) != gserialized_get_srid(geom2) )
-       {
-               elog(ERROR, "Operation on two geometries with different SRIDs");
-               PG_RETURN_NULL();
-       }
+
+       error_if_srid_mismatch(gserialized_get_srid(geom1), gserialized_get_srid(geom2));
 
        lwline = lwgeom_as_lwline(lwgeom_from_gserialized(geom1));
        lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom2));
index 53af49a008758f36da95fd6649ea7f12c609858f..2e57e09c16bcc1470c7473c70d8eee7eb91cfd00 100644 (file)
@@ -3469,11 +3469,7 @@ Datum polygonize_garray(PG_FUNCTION_ARGS)
                }
                else
                {
-                       if ( srid != gserialized_get_srid(geom) )
-                       {
-                               elog(ERROR, "polygonize: operation on mixed SRID geometries");
-                               PG_RETURN_NULL();
-                       }
+                       error_if_srid_mismatch(srid, gserialized_get_srid(geom));
                }
        }