PostGIS  3.1.6dev-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 743 of file measures.c.

744 {
745  POINTARRAY *pa = line->points;
746  const POINT2D *pt = getPoint2d_cp(pa, 0);
747 
748  /* Line has a pount outside poly. Check distance to outer ring only. */
749  if (ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE || dl->mode == DIST_MAX)
750  return lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl);
751 
752  for (uint32_t i = 1; i < poly->nrings; i++)
753  {
754  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[i], dl))
755  return LW_FALSE;
756 
757  /* just a check if the answer is already given */
758  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
759  return LW_TRUE;
760  }
761 
762  /* It's inside a hole, then the actual distance is the min ring distance */
763  for (uint32_t i = 1; i < poly->nrings; i++)
764  if (ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE)
765  return LW_TRUE;
766 
767  /* Not in hole, so inside polygon */
768  if (dl->mode == DIST_MIN)
769  {
770  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
771  }
772  return LW_TRUE;
773 }
#define LW_FALSE
Definition: liblwgeom.h:108
#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:740
#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:101
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:78
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1186
#define DIST_MIN
Definition: measures.h:44
#define DIST_MAX
Definition: measures.h:43
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
POINTARRAY * points
Definition: liblwgeom.h:497
POINTARRAY ** rings
Definition: liblwgeom.h:533
uint32_t nrings
Definition: liblwgeom.h:538

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_distpts_set(), lw_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, DISTPTS::mode, LWPOLY::nrings, LWLINE::points, ptarray_contains_point(), LWPOLY::rings, and DISTPTS::tolerance.

Referenced by lw_dist2d_distribute_bruteforce().

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