From fb7ab3a9a3d79166e14bc7f81a9410df0be3e39b Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 10 Mar 2010 15:29:39 +0000 Subject: [PATCH] Since we do a full scan of pointarray from ptarray_locate_point, take the chance to also return min distance git-svn-id: http://svn.osgeo.org/postgis/trunk@5395 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h | 7 +++++-- liblwgeom/ptarray.c | 5 ++++- postgis/lwgeom_functions_analytic.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index 2c69fe132..7f097e201 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -1394,9 +1394,12 @@ extern POINTARRAY *ptarray_substring(POINTARRAY *, double, double); /* * Given a point, returns the location of closest point on pointarray - * as a fraction of total length (0: first point -- 1: last point) + * as a fraction of total length (0: first point -- 1: last point). + * + * If not-null, the third argument will be set to the actual distance + * of the point from the pointarray. */ -extern double ptarray_locate_point(POINTARRAY *, POINT2D *); +extern double ptarray_locate_point(POINTARRAY *, POINT2D *, double *); /* * Write into *ret the coordinates of the closest point on diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index e68433c5a..7e9f007e5 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -778,9 +778,10 @@ closest_point_on_segment(POINT2D *p, POINT2D *A, POINT2D *B, POINT2D *ret) /* * Given a point, returns the location of closest point on pointarray + * and, optionally, it's actual distance from the point array. */ double -ptarray_locate_point(POINTARRAY *pa, POINT2D *p) +ptarray_locate_point(POINTARRAY *pa, POINT2D *p, double* mindistout) { double mindist=-1; double tlen, plen; @@ -844,6 +845,8 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p) LWDEBUGF(3, "plen %g, tlen %g", plen, tlen); LWDEBUGF(3, "mindist: %g", mindist); + if ( mindistout ) *mindistout = mindist; + return plen/tlen; } diff --git a/postgis/lwgeom_functions_analytic.c b/postgis/lwgeom_functions_analytic.c index 2a53994bb..c0e8b1f8c 100644 --- a/postgis/lwgeom_functions_analytic.c +++ b/postgis/lwgeom_functions_analytic.c @@ -1232,7 +1232,7 @@ Datum LWGEOM_line_locate_point(PG_FUNCTION_ARGS) pa = lwline->points; lwpoint_getPoint2d_p(lwpoint, &p); - ret = ptarray_locate_point(pa, &p); + ret = ptarray_locate_point(pa, &p, NULL); PG_RETURN_FLOAT8(ret); } -- 2.40.0