PostGIS  2.1.10dev-r@@SVN_REVISION@@
double ptarray_length ( const POINTARRAY pts)

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

Definition at line 1614 of file ptarray.c.

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

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

1615 {
1616  double dist = 0.0;
1617  int i;
1618  POINT3DZ frm;
1619  POINT3DZ to;
1620 
1621  if ( pts->npoints < 2 ) return 0.0;
1622 
1623  /* compute 2d length if 3d is not available */
1624  if ( ! FLAGS_GET_Z(pts->flags) ) return ptarray_length_2d(pts);
1625 
1626  getPoint3dz_p(pts, 0, &frm);
1627  for ( i=1; i < pts->npoints; i++ )
1628  {
1629  getPoint3dz_p(pts, i, &to);
1630  dist += sqrt( ((frm.x - to.x)*(frm.x - to.x)) +
1631  ((frm.y - to.y)*(frm.y - to.y)) +
1632  ((frm.z - to.z)*(frm.z - to.z)) );
1633  frm = to;
1634  }
1635  return dist;
1636 }
double z
Definition: liblwgeom.h:290
double y
Definition: liblwgeom.h:290
double x
Definition: liblwgeom.h:290
int npoints
Definition: liblwgeom.h:327
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:305
uint8_t flags
Definition: liblwgeom.h:325
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1586

Here is the call graph for this function:

Here is the caller graph for this function: