PostGIS  3.4.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 672 of file lwline.c.

673 {
674  POINTARRAY *pa, *opa;
675  POINT4D p00, p01, p10, p11;
676  POINT4D p_start, p_end;
677  uint32_t i;
678  bool forward = false, backward = false;
679 
680  if (distance_forward < 0 || distance_backward < 0)
681  lwerror("%s: distances must be non-negative", __func__);
682 
683  if (!line || lwline_is_empty(line) || lwline_count_vertices(line) < 2)
684  {
685  lwerror("%s: line must have at least two points", __func__);
686  }
687 
688  pa = line->points;
689  if (distance_backward > 0.0)
690  {
691  i = 0;
692  /* Get two distinct points at start of pointarray */
693  getPoint4d_p(pa, i++, &p00);
694  getPoint4d_p(pa, i, &p01);
695  while(p4d_same(&p00, &p01))
696  {
697  if (i == pa->npoints - 1)
698  {
699  lwerror("%s: line must have at least two distinct points", __func__);
700  }
701  i++;
702  getPoint4d_p(pa, i, &p01);
703  }
704  project_pt_pt(&p01, &p00, distance_backward, &p_start);
705  backward = true;
706  }
707 
708  if (distance_forward > 0.0)
709  {
710  i = pa->npoints - 1;
711  /* Get two distinct points at end of pointarray */
712  getPoint4d_p(pa, i--, &p10);
713  getPoint4d_p(pa, i, &p11);
714  while(p4d_same(&p10, &p11))
715  {
716  if (i == 0)
717  {
718  lwerror("%s: line must have at least two distinct points", __func__);
719  }
720  i--;
721  getPoint4d_p(pa, i, &p11);
722  }
723  project_pt_pt(&p11, &p10, distance_forward, &p_end);
724  forward = true;
725  }
726 
728 
729  if (backward)
730  {
731  ptarray_append_point(opa, &p_start, true);
732  }
733  ptarray_append_ptarray(opa, pa, -1.0);
734  if (forward)
735  {
736  ptarray_append_point(opa, &p_end, true);
737  }
738  return lwline_construct(line->srid, NULL, opa);
739 }
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:2499
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:44
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t lwline_count_vertices(const LWLINE *line)
Definition: lwline.c:505
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: