PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwpoly_intersects_line()

int lwpoly_intersects_line ( const LWPOLY lwpoly,
const POINTARRAY line 
)

Checks if any edges of lwpoly intersect with the line formed by the pointarray return LW_TRUE if any intersection between the given polygon and the line.

Definition at line 2715 of file lwgeodetic.c.

2716 {
2717  uint32_t i, j, k;
2718  POINT3D pa1, pa2, pb1, pb2;
2719  for (i = 0; i < lwpoly->nrings; i++)
2720  {
2721  for (j = 0; j < lwpoly->rings[i]->npoints - 1; j++)
2722  {
2723  const POINT2D* a1 = getPoint2d_cp(lwpoly->rings[i], j);
2724  const POINT2D* a2 = getPoint2d_cp(lwpoly->rings[i], j+1);
2725 
2726  /* Set up our stab line */
2727  ll2cart(a1, &pa1);
2728  ll2cart(a2, &pa2);
2729 
2730  for (k = 0; k < line->npoints - 1; k++)
2731  {
2732  const POINT2D* b1 = getPoint2d_cp(line, k);
2733  const POINT2D* b2 = getPoint2d_cp(line, k+1);
2734 
2735  /* Set up our stab line */
2736  ll2cart(b1, &pb1);
2737  ll2cart(b2, &pb2);
2738 
2739  int inter = edge_intersects(&pa1, &pa2, &pb1, &pb2);
2740 
2741  /* ignore same edges */
2742  if (inter & PIR_INTERSECTS
2743  && !(inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR) )
2744  {
2745  return LW_TRUE;
2746  }
2747  }
2748  }
2749  }
2750 
2751  return LW_FALSE;
2752 }
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
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:374
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:423
uint32_t edge_intersects(const POINT3D *A1, const POINT3D *A2, const POINT3D *B1, const POINT3D *B2)
Returns non-zero if edges A and B interact.
Definition: lwgeodetic.c:3540
#define PIR_COLINEAR
Definition: lwgeodetic.h:88
#define PIR_INTERSECTS
Definition: lwgeodetic.h:87
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:91
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint32_t nrings
Definition: liblwgeom.h:458
uint32_t npoints
Definition: liblwgeom.h:374
unsigned int uint32_t
Definition: uthash.h:78

References edge_intersects(), getPoint2d_cp(), ll2cart(), LW_FALSE, LW_TRUE, POINTARRAY::npoints, LWPOLY::nrings, PIR_B_TOUCH_RIGHT, PIR_COLINEAR, PIR_INTERSECTS, and LWPOLY::rings.

Referenced by lwpoly_covers_lwline(), and lwpoly_covers_lwpoly().

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