PostGIS  2.5.0dev-r@@SVN_REVISION@@
int lwline_covers_lwline ( const LWLINE lwline1,
const LWLINE lwline2 
)

Check if first and last point of line2 are covered by line1 and then each point in between has to be one line1 in the exact same order return LW_TRUE if all edge points of line2 are on line1.

Definition at line 2686 of file lwgeodetic.c.

References edge_contains_point(), GEOGRAPHIC_EDGE::end, geographic_point_init(), getPoint2d_cp(), LW_FALSE, LW_TRUE, LWDEBUG, lwline_covers_lwpoint(), lwline_get_lwpoint(), POINTARRAY::npoints, LWLINE::points, GEOGRAPHIC_EDGE::start, POINT2D::x, and POINT2D::y.

Referenced by lwgeom_covers_lwgeom_sphere().

2687 {
2688  uint32_t i, j;
2689  GEOGRAPHIC_EDGE e1, e2;
2690  GEOGRAPHIC_POINT p1, p2;
2691  int start = LW_FALSE;
2692  int changed = LW_FALSE;
2693 
2694  /* first point on line */
2695  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, 0)))
2696  {
2697  LWDEBUG(4,"returning false, first point of line2 is not covered by line1");
2698  return LW_FALSE;
2699  }
2700 
2701  /* last point on line */
2702  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, lwline2->points->npoints - 1)))
2703  {
2704  LWDEBUG(4,"returning false, last point of line2 is not covered by line1");
2705  return LW_FALSE;
2706  }
2707 
2708  j = 0;
2709  i = 0;
2710  while (i < lwline1->points->npoints - 1 && j < lwline2->points->npoints - 1)
2711  {
2712  changed = LW_FALSE;
2713  const POINT2D* a1 = getPoint2d_cp(lwline1->points, i);
2714  const POINT2D* a2 = getPoint2d_cp(lwline1->points, i+1);
2715  const POINT2D* b1 = getPoint2d_cp(lwline2->points, j);
2716  const POINT2D* b2 = getPoint2d_cp(lwline2->points, j+1);
2717 
2718  geographic_point_init(a1->x, a1->y, &(e1.start));
2719  geographic_point_init(a2->x, a2->y, &(e1.end));
2720  geographic_point_init(b1->x, b1->y, &p2);
2721 
2722  /* we already know, that the last point is on line1, so we're done */
2723  if ( j == lwline2->points->npoints - 1)
2724  {
2725  return LW_TRUE;
2726  }
2727  else if (start == LW_TRUE)
2728  {
2729  /* point is on current line1 edge, check next point in line2 */
2730  if ( edge_contains_point(&e1, &p2)) {
2731  j++;
2732  changed = LW_TRUE;
2733  }
2734 
2735  geographic_point_init(a1->x, a1->y, &(e2.start));
2736  geographic_point_init(a2->x, b2->y, &(e2.end));
2737  geographic_point_init(a1->x, a1->y, &p1);
2738 
2739  /* point is on current line2 edge, check next point in line1 */
2740  if ( edge_contains_point(&e2, &p1)) {
2741  i++;
2742  changed = LW_TRUE;
2743  }
2744 
2745  /* no edge progressed -> point left one line */
2746  if ( changed == LW_FALSE )
2747  {
2748  LWDEBUG(4,"returning false, found point not covered by both lines");
2749  return LW_FALSE;
2750  }
2751  else
2752  {
2753  continue;
2754  }
2755  }
2756 
2757  /* find first edge to cover line2 */
2758  if (edge_contains_point(&e1, &p2))
2759  {
2760  start = LW_TRUE;
2761  }
2762 
2763  /* next line1 edge */
2764  i++;
2765  }
2766 
2767  /* no uncovered point found */
2768  return LW_TRUE;
2769 }
Two-point great circle segment from a to b.
Definition: lwgeodetic.h:56
int edge_contains_point(const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
Returns true if the point p is on the minor edge defined by the end points of e.
Definition: lwgeodetic.c:999
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:327
#define LW_FALSE
Definition: liblwgeom.h:76
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:58
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:59
double y
Definition: liblwgeom.h:327
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
int lwline_covers_lwpoint(const LWLINE *lwline, const LWPOINT *lwpoint)
return LW_TRUE if any of the line segments covers the point
Definition: lwgeodetic.c:2657
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
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
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: