PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ptarray_length()

double ptarray_length ( const POINTARRAY pts)

Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)

Definition at line 1847 of file ptarray.c.

1848 {
1849  double dist = 0.0;
1850  uint32_t i;
1851  POINT3DZ frm;
1852  POINT3DZ to;
1853 
1854  if ( pts->npoints < 2 ) return 0.0;
1855 
1856  /* compute 2d length if 3d is not available */
1857  if ( ! FLAGS_GET_Z(pts->flags) ) return ptarray_length_2d(pts);
1858 
1859  getPoint3dz_p(pts, 0, &frm);
1860  for ( i=1; i < pts->npoints; i++ )
1861  {
1862  getPoint3dz_p(pts, i, &to);
1863  dist += sqrt( ((frm.x - to.x)*(frm.x - to.x)) +
1864  ((frm.y - to.y)*(frm.y - to.y)) +
1865  ((frm.z - to.z)*(frm.z - to.z)) );
1866  frm = to;
1867  }
1868  return dist;
1869 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:180
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:216
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1819
double z
Definition: liblwgeom.h:411
double x
Definition: liblwgeom.h:411
double y
Definition: liblwgeom.h:411
lwflags_t flags
Definition: liblwgeom.h:446
uint32_t npoints
Definition: liblwgeom.h:442

References POINTARRAY::flags, FLAGS_GET_Z, getPoint3dz_p(), POINTARRAY::npoints, ptarray_length_2d(), POINT3DZ::x, POINT3DZ::y, and POINT3DZ::z.

Referenced by lwline_interpolate_point_3d(), lwline_length(), lwpoly_perimeter(), and lwtriangle_perimeter().

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