PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwline_extend()

LWLINE* lwline_extend ( const LWLINE line,
double  distance_forward,
double  distance_backward 
)

Extend the ends of a line.

Definition at line 682 of file lwline.c.

683 {
684  POINTARRAY *pa, *opa;
685  POINT4D p00, p01, p10, p11;
686  POINT4D p_start, p_end;
687  uint32_t i;
688  bool forward = false, backward = false;
689 
690  if (distance_forward < 0 || distance_backward < 0)
691  lwerror("%s: distances must be non-negative", __func__);
692 
693  if (!line || lwline_is_empty(line) || lwline_count_vertices(line) < 2)
694  {
695  lwerror("%s: line must have at least two points", __func__);
696  }
697 
698  pa = line->points;
699  if (distance_backward > 0.0)
700  {
701  i = 0;
702  /* Get two distinct points at start of pointarray */
703  getPoint4d_p(pa, i++, &p00);
704  getPoint4d_p(pa, i, &p01);
705  while(p4d_same(&p00, &p01))
706  {
707  if (i == pa->npoints - 1)
708  {
709  lwerror("%s: line must have at least two distinct points", __func__);
710  }
711  i++;
712  getPoint4d_p(pa, i, &p01);
713  }
714  project_pt_pt(&p01, &p00, distance_backward, &p_start);
715  backward = true;
716  }
717 
718  if (distance_forward > 0.0)
719  {
720  i = pa->npoints - 1;
721  /* Get two distinct points at end of pointarray */
722  getPoint4d_p(pa, i--, &p10);
723  getPoint4d_p(pa, i, &p11);
724  while(p4d_same(&p10, &p11))
725  {
726  if (i == 0)
727  {
728  lwerror("%s: line must have at least two distinct points", __func__);
729  }
730  i--;
731  getPoint4d_p(pa, i, &p11);
732  }
733  project_pt_pt(&p11, &p10, distance_forward, &p_end);
734  forward = true;
735  }
736 
738 
739  if (backward)
740  {
741  ptarray_append_point(opa, &p_start, true);
742  }
743  ptarray_append_ptarray(opa, pa, -1.0);
744  if (forward)
745  {
746  ptarray_append_point(opa, &p_end, true);
747  }
748  return lwline_construct(line->srid, NULL, opa);
749 }
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition: ptarray.c:177
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:147
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:32
int lwline_is_empty(const LWLINE *line)
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:37
int project_pt_pt(const POINT4D *A, const POINT4D *B, double distance, POINT4D *R)
Azimuth is angle in radians from vertical axis.
Definition: measures.c:2445
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:44
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
uint32_t lwline_count_vertices(const LWLINE *line)
Definition: lwline.c:515
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY * points
Definition: liblwgeom.h:483
int32_t srid
Definition: liblwgeom.h:484
uint32_t npoints
Definition: liblwgeom.h:427

References getPoint4d_p(), lwerror(), lwline_construct(), lwline_count_vertices(), lwline_is_empty(), POINTARRAY::npoints, p4d_same(), LWLINE::points, project_pt_pt(), ptarray_append_point(), ptarray_append_ptarray(), ptarray_construct_empty(), ptarray_has_m(), ptarray_has_z(), and LWLINE::srid.

Referenced by geometry_line_extend().

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