From: Paul Ramsey Date: Sat, 8 Mar 2014 00:45:32 +0000 (+0000) Subject: #2636, Regress ST_Distance_Sphere between 2.1.2dev and 2.0.4 with 2D X-Git-Tag: 2.2.0rc1~1204 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44cf4543aa2f8e4ed52b77120bf74f712217f300;p=postgis #2636, Regress ST_Distance_Sphere between 2.1.2dev and 2.0.4 with 2D git-svn-id: http://svn.osgeo.org/postgis/trunk@12307 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeodetic.c b/liblwgeom/lwgeodetic.c index 214d64db6..be5a9255b 100644 --- a/liblwgeom/lwgeodetic.c +++ b/liblwgeom/lwgeodetic.c @@ -1815,7 +1815,13 @@ static double ptarray_distance_spheroid(const POINTARRAY *pa1, const POINTARRAY e1.start = e1.end; } - return spheroid_distance(&g1, &nearest2, s); + /* On sphere, return answer */ + if ( use_sphere ) + return distance; + /* On spheroid, calculate final answer based on closest approach */ + else + return spheroid_distance(&g1, &nearest2, s); + } /* Initialize start of line 1 */ diff --git a/liblwgeom/lwgeodetic_tree.c b/liblwgeom/lwgeodetic_tree.c index 19da35aed..383f6ac75 100644 --- a/liblwgeom/lwgeodetic_tree.c +++ b/liblwgeom/lwgeodetic_tree.c @@ -522,13 +522,19 @@ circ_tree_distance_tree(const CIRC_NODE* n1, const CIRC_NODE* n2, const SPHEROID double min_dist = MAXFLOAT; double max_dist = MAXFLOAT; GEOGRAPHIC_POINT closest1, closest2; - double distance2; double threshold_radians = threshold / spheroid->radius; circ_tree_distance_tree_internal(n1, n2, threshold_radians, &min_dist, &max_dist, &closest1, &closest2); - distance2 = spheroid_distance(&closest1, &closest2, spheroid); - return distance2; + /* Spherical case */ + if ( spheroid->a == spheroid->b ) + { + return spheroid->radius * sphere_distance(&closest1, &closest2); + } + else + { + return spheroid_distance(&closest1, &closest2, spheroid); + } } static double