mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-24 09:02:37 +00:00
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
This commit is contained in:
parent
c2eac6cc1a
commit
fb7ab3a9a3
|
@ -1394,9 +1394,12 @@ extern POINTARRAY *ptarray_substring(POINTARRAY *, double, double);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Given a point, returns the location of closest point on pointarray
|
* 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
|
* Write into *ret the coordinates of the closest point on
|
||||||
|
|
|
@ -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
|
* Given a point, returns the location of closest point on pointarray
|
||||||
|
* and, optionally, it's actual distance from the point array.
|
||||||
*/
|
*/
|
||||||
double
|
double
|
||||||
ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
|
ptarray_locate_point(POINTARRAY *pa, POINT2D *p, double* mindistout)
|
||||||
{
|
{
|
||||||
double mindist=-1;
|
double mindist=-1;
|
||||||
double tlen, plen;
|
double tlen, plen;
|
||||||
|
@ -844,6 +845,8 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
|
||||||
LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
|
LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
|
||||||
LWDEBUGF(3, "mindist: %g", mindist);
|
LWDEBUGF(3, "mindist: %g", mindist);
|
||||||
|
|
||||||
|
if ( mindistout ) *mindistout = mindist;
|
||||||
|
|
||||||
return plen/tlen;
|
return plen/tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1232,7 +1232,7 @@ Datum LWGEOM_line_locate_point(PG_FUNCTION_ARGS)
|
||||||
pa = lwline->points;
|
pa = lwline->points;
|
||||||
lwpoint_getPoint2d_p(lwpoint, &p);
|
lwpoint_getPoint2d_p(lwpoint, &p);
|
||||||
|
|
||||||
ret = ptarray_locate_point(pa, &p);
|
ret = ptarray_locate_point(pa, &p, NULL);
|
||||||
|
|
||||||
PG_RETURN_FLOAT8(ret);
|
PG_RETURN_FLOAT8(ret);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue