PostGIS  2.2.8dev-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 597 of file measures.c.

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_pt_ptarray(), LW_OUTSIDE, LW_TRUE, LWDEBUG, 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().

598 {
599  const POINT2D *p;
600  int i;
601 
602  LWDEBUG(2, "lw_dist2d_point_poly called");
603 
604  p = getPoint2d_cp(point->point, 0);
605 
606  if (dl->mode == DIST_MAX)
607  {
608  LWDEBUG(3, "looking for maxdistance");
609  return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
610  }
611  /* Return distance to outer ring if not inside it */
612  if ( ptarray_contains_point(poly->rings[0], p) == LW_OUTSIDE )
613  {
614  LWDEBUG(3, "first point not inside outer-ring");
615  return lw_dist2d_pt_ptarray(p, poly->rings[0], dl);
616  }
617 
618  /*
619  * Inside the outer ring.
620  * Scan though each of the inner rings looking to
621  * see if its inside. If not, distance==0.
622  * Otherwise, distance = pt to ring distance
623  */
624  for ( i = 1; i < poly->nrings; i++)
625  {
626  /* Inside a hole. Distance = pt -> ring */
627  if ( ptarray_contains_point(poly->rings[i], p) != LW_OUTSIDE )
628  {
629  LWDEBUG(3, " inside an hole");
630  return lw_dist2d_pt_ptarray(p, poly->rings[i], dl);
631  }
632  }
633 
634  LWDEBUG(3, " inside the polygon");
635  if (dl->mode == DIST_MIN)
636  {
637  dl->distance = 0.0;
638  dl->p1.x = dl->p2.x = p->x;
639  dl->p1.y = dl->p2.y = p->y;
640  }
641  return LW_TRUE; /* Is inside the polygon */
642 }
int mode
Definition: measures.h:27
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINTARRAY * point
Definition: liblwgeom.h:395
POINT2D p1
Definition: measures.h:25
double x
Definition: liblwgeom.h:312
#define DIST_MIN
Definition: measures.h:17
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
POINTARRAY ** rings
Definition: liblwgeom.h:441
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:1035
POINT2D p2
Definition: measures.h:26
int nrings
Definition: liblwgeom.h:439
double y
Definition: liblwgeom.h:312
double distance
Definition: measures.h:24
#define DIST_MAX
Definition: measures.h:16
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:733
#define LW_OUTSIDE
Here is the call graph for this function:
Here is the caller graph for this function: