PostGIS  2.3.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 733 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().

734 {
735  const POINT2D *pt;
736  int i;
737 
738  LWDEBUGF(2, "lw_dist2d_line_poly called (%d rings)", poly->nrings);
739 
740  pt = getPoint2d_cp(line->points, 0);
741  if ( ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE )
742  {
743  return lw_dist2d_ptarray_ptarray(line->points, poly->rings[0], dl);
744  }
745 
746  for (i=1; i<poly->nrings; i++)
747  {
748  if (!lw_dist2d_ptarray_ptarray(line->points, poly->rings[i], dl)) return LW_FALSE;
749 
750  LWDEBUGF(3, " distance from ring %d: %f, mindist: %f",
751  i, dl->distance, dl->tolerance);
752  /* just a check if the answer is already given */
753  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE;
754  }
755 
756  /*
757  * No intersection, have to check if a point is
758  * inside polygon
759  */
760  pt = getPoint2d_cp(line->points, 0);
761 
762  /*
763  * Outside outer ring, so min distance to a ring
764  * is the actual min distance
765 
766  if ( ! pt_in_ring_2d(&pt, poly->rings[0]) )
767  {
768  return ;
769  } */
770 
771  /*
772  * Its in the outer ring.
773  * Have to check if its inside a hole
774  */
775  for (i=1; i<poly->nrings; i++)
776  {
777  if ( ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE )
778  {
779  /*
780  * Its inside a hole, then the actual
781  * distance is the min ring distance
782  */
783  return LW_TRUE;
784  }
785  }
786  if (dl->mode == DIST_MIN)
787  {
788  dl->distance = 0.0;
789  dl->p1.x = dl->p2.x = pt->x;
790  dl->p1.y = dl->p2.y = pt->y;
791  }
792  return LW_TRUE; /* Not in hole, so inside polygon */
793 }
int mode
Definition: measures.h:51
POINT2D p1
Definition: measures.h:49
double tolerance
Definition: measures.h:53
double x
Definition: liblwgeom.h:327
#define DIST_MIN
Definition: measures.h:41
#define LW_FALSE
Definition: liblwgeom.h:76
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:485
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
POINTARRAY ** rings
Definition: liblwgeom.h:456
POINT2D p2
Definition: measures.h:50
int nrings
Definition: liblwgeom.h:454
double y
Definition: liblwgeom.h:327
double distance
Definition: measures.h:48
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:740
#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:1131
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
POINTARRAY * points
Definition: liblwgeom.h:421
Here is the call graph for this function:
Here is the caller graph for this function: