PostGIS  2.5.0beta2dev-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 737 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().

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