PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lw_dist2d_point_poly()

int lw_dist2d_point_poly ( LWPOINT point,
LWPOLY poly,
DISTPTS dl 
)
  1. see if pt in outer boundary. if no, then treat the outer ring like a line
  2. if in the boundary, test to see if its in a hole. if so, then return dist to hole, else return 0 (point in polygon)

Definition at line 656 of file measures.c.

657{
658 const POINT2D *p = getPoint2d_cp(point->point, 0);
659
660 /* Max distance? Check only outer ring.*/
661 if (dl->mode == DIST_MAX)
662 return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
663
664 /* Return distance to outer ring if not inside it */
665 if (ptarray_contains_point(poly->rings[0], p) == LW_OUTSIDE)
666 return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
667
668 /*
669 * Inside the outer ring.
670 * Scan though each of the inner rings looking to
671 * see if its inside. If not, distance==0.
672 * Otherwise, distance = pt to ring distance
673 */
674 for (uint32_t i = 1; i < poly->nrings; i++)
675 if (ptarray_contains_point(poly->rings[i], p) != LW_OUTSIDE)
676 return lw_dist2d_pt_ptarray(p, poly->rings[i], dl);
677
678 /* Is inside the polygon */
679 lw_dist2d_distpts_set(dl, 0.0, p, p);
680 return LW_TRUE;
681}
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
The following is based on the "Fast Winding Number Inclusion of a Point in a Polygon" algorithm by Da...
Definition ptarray.c:755
#define LW_OUTSIDE
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition lwinline.h:97
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition measures.c:81
int lw_dist2d_pt_ptarray(const POINT2D *p, POINTARRAY *pa, DISTPTS *dl)
search all the segments of pointarray to see which one is closest to p1 Returns minimum distance betw...
Definition measures.c:1112
#define DIST_MAX
Definition measures.h:43
int mode
Definition measures.h:54
POINTARRAY * point
Definition liblwgeom.h:471
POINTARRAY ** rings
Definition liblwgeom.h:519
uint32_t nrings
Definition liblwgeom.h:524

References DIST_MAX, getPoint2d_cp(), lw_dist2d_distpts_set(), lw_dist2d_pt_ptarray(), LW_OUTSIDE, LW_TRUE, DISTPTS::mode, LWPOLY::nrings, LWPOINT::point, ptarray_contains_point(), and LWPOLY::rings.

Referenced by lw_dist2d_distribute_bruteforce().

Here is the call graph for this function:
Here is the caller graph for this function: