PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ 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 641 of file measures.c.

642 {
643  const POINT2D *p = getPoint2d_cp(point->point, 0);
644 
645  /* Max distance? Check only outer ring.*/
646  if (dl->mode == DIST_MAX)
647  return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
648 
649  /* Return distance to outer ring if not inside it */
650  if (ptarray_contains_point(poly->rings[0], p) == LW_OUTSIDE)
651  return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
652 
653  /*
654  * Inside the outer ring.
655  * Scan though each of the inner rings looking to
656  * see if its inside. If not, distance==0.
657  * Otherwise, distance = pt to ring distance
658  */
659  for (uint32_t i = 1; i < poly->nrings; i++)
660  if (ptarray_contains_point(poly->rings[i], p) != LW_OUTSIDE)
661  return lw_dist2d_pt_ptarray(p, poly->rings[i], dl);
662 
663  /* Is inside the polygon */
664  dl->distance = 0.0;
665  dl->p1.x = dl->p2.x = p->x;
666  dl->p1.y = dl->p2.y = p->y;
667  return LW_TRUE;
668 }
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary.
Definition: ptarray.c:732
#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:91
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:1129
#define DIST_MAX
Definition: measures.h:43
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
POINTARRAY * point
Definition: liblwgeom.h:457
POINTARRAY ** rings
Definition: liblwgeom.h:505
uint32_t nrings
Definition: liblwgeom.h:510
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376

References DIST_MAX, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_pt_ptarray(), LW_OUTSIDE, LW_TRUE, DISTPTS::mode, LWPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWPOINT::point, ptarray_contains_point(), LWPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce().

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