From d5f937c27c0ae2d7f0998c22c4844ce4f80c0347 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 22 Jul 2015 13:37:07 +0000 Subject: [PATCH] Harmonize SRID mismatch handling to use same function git-svn-id: http://svn.osgeo.org/postgis/trunk@13824 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_btree.c | 57 ++--------------- postgis/lwgeom_functions_basic.c | 104 ++++++------------------------- postgis/lwgeom_functions_lrs.c | 15 ++--- postgis/lwgeom_geos.c | 6 +- 4 files changed, 30 insertions(+), 152 deletions(-) diff --git a/postgis/lwgeom_btree.c b/postgis/lwgeom_btree.c index 3553ea5ea..b891ebe88 100644 --- a/postgis/lwgeom_btree.c +++ b/postgis/lwgeom_btree.c @@ -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); diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 4c2e585e0..9ab8f41c6 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -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) { diff --git a/postgis/lwgeom_functions_lrs.c b/postgis/lwgeom_functions_lrs.c index 55ed13209..4e038f5e8 100644 --- a/postgis/lwgeom_functions_lrs.c +++ b/postgis/lwgeom_functions_lrs.c @@ -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)); diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 53af49a00..2e57e09c1 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -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)); } } -- 2.50.1