PostGIS  2.5.0dev-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 2628 of file lwgeodetic.c.

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().

2629 {
2630  uint32_t i, j, k;
2631  POINT3D pa1, pa2, pb1, pb2;
2632  for (i = 0; i < lwpoly->nrings; i++)
2633  {
2634  for (j = 0; j < lwpoly->rings[i]->npoints - 1; j++)
2635  {
2636  const POINT2D* a1 = getPoint2d_cp(lwpoly->rings[i], j);
2637  const POINT2D* a2 = getPoint2d_cp(lwpoly->rings[i], j+1);
2638 
2639  /* Set up our stab line */
2640  ll2cart(a1, &pa1);
2641  ll2cart(a2, &pa2);
2642 
2643  for (k = 0; k < line->npoints - 1; k++)
2644  {
2645  const POINT2D* b1 = getPoint2d_cp(line, k);
2646  const POINT2D* b2 = getPoint2d_cp(line, k+1);
2647 
2648  /* Set up our stab line */
2649  ll2cart(b1, &pb1);
2650  ll2cart(b2, &pb2);
2651 
2652  int inter = edge_intersects(&pa1, &pa2, &pb1, &pb2);
2653 
2654  /* ignore same edges */
2655  if (inter & PIR_INTERSECTS
2656  && !(inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR) )
2657  {
2658  return LW_TRUE;
2659  }
2660  }
2661  }
2662  }
2663 
2664  return LW_FALSE;
2665 }
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:86
uint32_t nrings
Definition: liblwgeom.h:457
unsigned int uint32_t
Definition: uthash.h:78
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:392
POINTARRAY ** rings
Definition: liblwgeom.h:459
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:3424
#define PIR_COLINEAR
Definition: lwgeodetic.h:83
#define PIR_INTERSECTS
Definition: lwgeodetic.h:82
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
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: