From 8fd6bd1e323ff0abbc5e62b57dfbce31814cd042 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicklas=20Av=C3=A9n?= Date: Tue, 14 Jul 2015 16:14:49 +0000 Subject: [PATCH] Fix wrong behavior for closest point with unknown z-value in geometry 1 from last commit git-svn-id: http://svn.osgeo.org/postgis/trunk@13803 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/measures3d.c | 21 ++++++++++++++++++++- regress/measures_expected | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/liblwgeom/measures3d.c b/liblwgeom/measures3d.c index 6878e7475..c4d04fa20 100644 --- a/liblwgeom/measures3d.c +++ b/liblwgeom/measures3d.c @@ -188,7 +188,7 @@ lw_dist3d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int srid, int mode lwnotice("One or both of the geometries is missing z-value. The unknown z-value will be regarded as 'any value'"); - if(!lwgeom_has_z(lw2)) + if(!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2)) return lw_dist2d_distancepoint(lw1, lw2, srid, mode); @@ -221,6 +221,25 @@ lw_dist3d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int srid, int mode result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0); } } + + if(!lwgeom_has_z(lw2)) + { + LWPOINT *lwpoints[2]; + LWGEOM *new_lw2; + x=thedl2d.p2.x; + y=thedl2d.p2.y; + + lwpoints[0] = lwpoint_make3dz(srid, x, y, FLT_MIN); + lwpoints[1] = lwpoint_make3dz(srid, x, y, FLT_MAX); + + new_lw2 = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints); + if (!lw_dist3d_recursive(lw1, new_lw2, &thedl)) + { + /*should never get here. all cases ought to be error handled earlier*/ + lwerror("Some unspecified error."); + result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0); + } + } } else diff --git a/regress/measures_expected b/regress/measures_expected index 352a8f7d2..c43f4ab02 100644 --- a/regress/measures_expected +++ b/regress/measures_expected @@ -38,7 +38,7 @@ distancepoly6|0|32.5269119345812|LINESTRING(2 2,2 2)|LINESTRING(2 2,2 2)|LINESTR NOTICE: One or both of the geometries is missing z-value. The unknown z-value will be regarded as 'any value' POINT Z (1 1 3) NOTICE: One or both of the geometries is missing z-value. The unknown z-value will be regarded as 'any value' -POINT(1 1) +POINT Z (1 1 2) NOTICE: One or both of the geometries is missing z-value. The unknown z-value will be regarded as 'any value' LINESTRING Z (1 1 3,1 2 3) NOTICE: One or both of the geometries is missing z-value. The unknown z-value will be regarded as 'any value' -- 2.50.1