PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwline_covers_lwline()

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

2770 {
2771  int i, j;
2772  GEOGRAPHIC_EDGE e1, e2;
2773  GEOGRAPHIC_POINT p1, p2;
2774  int start = LW_FALSE;
2775  int changed = LW_FALSE;
2776 
2777  /* first point on line */
2778  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, 0)))
2779  {
2780  LWDEBUG(4,"returning false, first point of line2 is not covered by line1");
2781  return LW_FALSE;
2782  }
2783 
2784  /* last point on line */
2785  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, lwline2->points->npoints - 1)))
2786  {
2787  LWDEBUG(4,"returning false, last point of line2 is not covered by line1");
2788  return LW_FALSE;
2789  }
2790 
2791  j = 0;
2792  i = 0;
2793  while (i < lwline1->points->npoints - 1 && j < lwline2->points->npoints - 1)
2794  {
2795  changed = LW_FALSE;
2796  const POINT2D* a1 = getPoint2d_cp(lwline1->points, i);
2797  const POINT2D* a2 = getPoint2d_cp(lwline1->points, i+1);
2798  const POINT2D* b1 = getPoint2d_cp(lwline2->points, j);
2799  const POINT2D* b2 = getPoint2d_cp(lwline2->points, j+1);
2800 
2801  geographic_point_init(a1->x, a1->y, &(e1.start));
2802  geographic_point_init(a2->x, a2->y, &(e1.end));
2803  geographic_point_init(b1->x, b1->y, &p2);
2804 
2805  /* we already know, that the last point is on line1, so we're done */
2806  if ( j == lwline2->points->npoints - 1)
2807  {
2808  return LW_TRUE;
2809  }
2810  else if (start == LW_TRUE)
2811  {
2812  /* point is on current line1 edge, check next point in line2 */
2813  if ( edge_contains_point(&e1, &p2)) {
2814  j++;
2815  changed = LW_TRUE;
2816  }
2817 
2818  geographic_point_init(a1->x, a1->y, &(e2.start));
2819  geographic_point_init(a2->x, b2->y, &(e2.end));
2820  geographic_point_init(a1->x, a1->y, &p1);
2821 
2822  /* point is on current line2 edge, check next point in line1 */
2823  if ( edge_contains_point(&e2, &p1)) {
2824  i++;
2825  changed = LW_TRUE;
2826  }
2827 
2828  /* no edge progressed -> point left one line */
2829  if ( changed == LW_FALSE )
2830  {
2831  LWDEBUG(4,"returning false, found point not covered by both lines");
2832  return LW_FALSE;
2833  }
2834  else
2835  {
2836  continue;
2837  }
2838  }
2839 
2840  /* find first edge to cover line2 */
2841  if (edge_contains_point(&e1, &p2))
2842  {
2843  start = LW_TRUE;
2844  }
2845 
2846  /* next line1 edge */
2847  i++;
2848  }
2849 
2850  /* no uncovered point found */
2851  return LW_TRUE;
2852 }
Two-point great circle segment from a to b.
Definition: lwgeodetic.h:61
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:1030
int npoints
Definition: liblwgeom.h:371
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
double x
Definition: liblwgeom.h:328
#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
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:63
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:64
double y
Definition: liblwgeom.h:328
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:324
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:2740
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: