PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lw_dist2d_line_poly()

int lw_dist2d_line_poly ( LWLINE line,
LWPOLY poly,
DISTPTS dl 
)

line to polygon calculation Brute force.

Test line-ring distance against each ring. If there's an intersection (distance==0) then return 0 (crosses boundary). Otherwise, test to see if any point is inside outer rings of polygon, but not in inner rings. If so, return 0 (line inside polygon), otherwise return min distance to a ring (could be outside polygon or inside a hole)

Definition at line 719 of file measures.c.

References DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, LWDEBUGF, DISTPTS::mode, LWPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWLINE::points, ptarray_contains_point(), LWPOLY::rings, DISTPTS::tolerance, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce().

720 {
721  const POINT2D *pt;
722  int i;
723 
724  LWDEBUGF(2, "lw_dist2d_line_poly called (%d rings)", poly->nrings);
725 
726  pt = getPoint2d_cp(line->points, 0);
727  if ( ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE )
728  {
729  return lw_dist2d_ptarray_ptarray(line->points, poly->rings[0], dl);
730  }
731 
732  for (i=1; i<poly->nrings; i++)
733  {
734  if (!lw_dist2d_ptarray_ptarray(line->points, poly->rings[i], dl)) return LW_FALSE;
735 
736  LWDEBUGF(3, " distance from ring %d: %f, mindist: %f",
737  i, dl->distance, dl->tolerance);
738  /* just a check if the answer is already given */
739  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE;
740  }
741 
742  /*
743  * No intersection, have to check if a point is
744  * inside polygon
745  */
746  pt = getPoint2d_cp(line->points, 0);
747 
748  /*
749  * Outside outer ring, so min distance to a ring
750  * is the actual min distance
751 
752  if ( ! pt_in_ring_2d(&pt, poly->rings[0]) )
753  {
754  return ;
755  } */
756 
757  /*
758  * Its in the outer ring.
759  * Have to check if its inside a hole
760  */
761  for (i=1; i<poly->nrings; i++)
762  {
763  if ( ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE )
764  {
765  /*
766  * Its inside a hole, then the actual
767  * distance is the min ring distance
768  */
769  return LW_TRUE;
770  }
771  }
772  if (dl->mode == DIST_MIN)
773  {
774  dl->distance = 0.0;
775  dl->p1.x = dl->p2.x = pt->x;
776  dl->p1.y = dl->p2.y = pt->y;
777  }
778  return LW_TRUE; /* Not in hole, so inside polygon */
779 }
int mode
Definition: measures.h:27
POINT2D p1
Definition: measures.h:25
double tolerance
Definition: measures.h:29
double x
Definition: liblwgeom.h:312
#define DIST_MIN
Definition: measures.h:17
#define LW_FALSE
Definition: liblwgeom.h:62
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
POINT2D p2
Definition: measures.h:26
int nrings
Definition: liblwgeom.h:439
double y
Definition: liblwgeom.h:312
double distance
Definition: measures.h:24
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
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1117
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
POINTARRAY * points
Definition: liblwgeom.h:406
Here is the call graph for this function:
Here is the caller graph for this function: