From ec001a4dfc51aaae2804bf2223594461b698478c Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 20 Jun 2011 16:58:07 +0000 Subject: [PATCH] geography: ST_Intersects, ST_DWithin gbox_overlaps: geometries have mismatched dimensionality (#1037) git-svn-id: http://svn.osgeo.org/postgis/trunk@7433 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/g_box.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/liblwgeom/g_box.c b/liblwgeom/g_box.c index 67620c716..6e87af17b 100644 --- a/liblwgeom/g_box.c +++ b/liblwgeom/g_box.c @@ -221,27 +221,30 @@ int gbox_merge(const GBOX *new_box, GBOX *merge_box) int gbox_overlaps(const GBOX *g1, const GBOX *g2) { - /* Make sure our boxes have the same dimensionality */ - if ( (FLAGS_GET_Z(g1->flags) != FLAGS_GET_Z(g2->flags)) || - (FLAGS_GET_M(g1->flags) != FLAGS_GET_M(g2->flags)) || - (FLAGS_GET_GEODETIC(g1->flags) != FLAGS_GET_GEODETIC(g2->flags)) ) - { - lwerror("gbox_overlaps: geometries have mismatched dimensionality"); - } + /* Make sure our boxes are consistent */ + if ( FLAGS_GET_GEODETIC(g1->flags) != FLAGS_GET_GEODETIC(g2->flags) ) + lwerror("gbox_overlaps: cannot compare geodetic and non-geodetic boxes"); + /* Check X/Y first */ if ( g1->xmax < g2->xmin || g1->ymax < g2->ymin || - g1->xmin > g2->xmax || g1->ymin > g2->ymax ) + g1->xmin > g2->xmax || g1->ymin > g2->ymax ) return LW_FALSE; - if ( FLAGS_GET_Z(g1->flags) || FLAGS_GET_GEODETIC(g1->flags) ) + + /* If both geodetic or both have Z, check Z */ + if ( (FLAGS_GET_Z(g1->flags) && FLAGS_GET_Z(g2->flags)) || + (FLAGS_GET_GEODETIC(g1->flags) && FLAGS_GET_GEODETIC(g2->flags)) ) { if ( g1->zmax < g2->zmin || g1->zmin > g2->zmax ) return LW_FALSE; } - if ( FLAGS_GET_M(g1->flags) ) + + /* If both have M, check M */ + if ( FLAGS_GET_M(g1->flags) && FLAGS_GET_M(g2->flags) ) { if ( g1->mmax < g2->mmin || g1->mmin > g2->mmax ) return LW_FALSE; } + return LW_TRUE; } -- 2.50.1