PostGIS  2.2.7dev-r@@SVN_REVISION@@
double lwgeom_length_spheroid ( const LWGEOM geom,
const SPHEROID s 
)

Calculate the geodetic length of a lwgeom on the unit sphere.

The result will have to by multiplied by the real radius to get the real length.

Definition at line 2884 of file lwgeodetic.c.

References LWCOLLECTION::geoms, LINETYPE, lwerror(), lwgeom_is_empty(), lwtype_is_collection(), MULTIPOINTTYPE, LWCOLLECTION::ngeoms, LWPOLY::nrings, POINTTYPE, POLYGONTYPE, ptarray_length_spheroid(), LWPOLY::rings, TRIANGLETYPE, and LWGEOM::type.

Referenced by geography_length(), geography_perimeter(), LWGEOM_length2d_ellipsoid(), and LWGEOM_length_ellipsoid_linestring().

2885 {
2886  int type;
2887  int i = 0;
2888  double length = 0.0;
2889 
2890  assert(geom);
2891 
2892  /* No area in nothing */
2893  if ( lwgeom_is_empty(geom) )
2894  return 0.0;
2895 
2896  type = geom->type;
2897 
2898  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
2899  return 0.0;
2900 
2901  if ( type == LINETYPE )
2902  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
2903 
2904  if ( type == POLYGONTYPE )
2905  {
2906  LWPOLY *poly = (LWPOLY*)geom;
2907  for ( i = 0; i < poly->nrings; i++ )
2908  {
2909  length += ptarray_length_spheroid(poly->rings[i], s);
2910  }
2911  return length;
2912  }
2913 
2914  if ( type == TRIANGLETYPE )
2915  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
2916 
2917  if ( lwtype_is_collection( type ) )
2918  {
2919  LWCOLLECTION *col = (LWCOLLECTION*)geom;
2920 
2921  for ( i = 0; i < col->ngeoms; i++ )
2922  {
2923  length += lwgeom_length_spheroid(col->geoms[i], s);
2924  }
2925  return length;
2926  }
2927 
2928  lwerror("unsupported type passed to lwgeom_length_sphere");
2929  return 0.0;
2930 }
#define LINETYPE
Definition: liblwgeom.h:71
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define TRIANGLETYPE
Definition: liblwgeom.h:83
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:2884
LWGEOM ** geoms
Definition: liblwgeom.h:493
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:2831
POINTARRAY ** rings
Definition: liblwgeom.h:441
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:999
int nrings
Definition: liblwgeom.h:439
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: