PostGIS  2.4.9dev-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 beetween the given polygon and the line.

Definition at line 2698 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().

2699 {
2700  int i, j, k;
2701  POINT3D pa1, pa2, pb1, pb2;
2702  for (i = 0; i < lwpoly->nrings; i++)
2703  {
2704  for (j = 0; j < lwpoly->rings[i]->npoints - 1; j++)
2705  {
2706  const POINT2D* a1 = getPoint2d_cp(lwpoly->rings[i], j);
2707  const POINT2D* a2 = getPoint2d_cp(lwpoly->rings[i], j+1);
2708 
2709  /* Set up our stab line */
2710  ll2cart(a1, &pa1);
2711  ll2cart(a2, &pa2);
2712 
2713  for (k = 0; k < line->npoints - 1; k++)
2714  {
2715  const POINT2D* b1 = getPoint2d_cp(line, k);
2716  const POINT2D* b2 = getPoint2d_cp(line, k+1);
2717 
2718  /* Set up our stab line */
2719  ll2cart(b1, &pb1);
2720  ll2cart(b2, &pb2);
2721 
2722  int inter = edge_intersects(&pa1, &pa2, &pb1, &pb2);
2723 
2724  /* ignore same edges */
2725  if (inter & PIR_INTERSECTS
2726  && !(inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR) )
2727  {
2728  return LW_TRUE;
2729  }
2730  }
2731  }
2732  }
2733 
2734  return LW_FALSE;
2735 }
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:91
int npoints
Definition: liblwgeom.h:371
#define LW_FALSE
Definition: liblwgeom.h:77
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:373
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:419
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
int 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:3525
#define PIR_COLINEAR
Definition: lwgeodetic.h:88
#define PIR_INTERSECTS
Definition: lwgeodetic.h:87
Here is the call graph for this function:
Here is the caller graph for this function: