PostGIS  2.1.10dev-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 2881 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().

2882 {
2883  int type;
2884  int i = 0;
2885  double length = 0.0;
2886 
2887  assert(geom);
2888 
2889  /* No area in nothing */
2890  if ( lwgeom_is_empty(geom) )
2891  return 0.0;
2892 
2893  type = geom->type;
2894 
2895  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
2896  return 0.0;
2897 
2898  if ( type == LINETYPE )
2899  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
2900 
2901  if ( type == POLYGONTYPE )
2902  {
2903  LWPOLY *poly = (LWPOLY*)geom;
2904  for ( i = 0; i < poly->nrings; i++ )
2905  {
2906  length += ptarray_length_spheroid(poly->rings[i], s);
2907  }
2908  return length;
2909  }
2910 
2911  if ( type == TRIANGLETYPE )
2912  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
2913 
2914  if ( lwtype_is_collection( type ) )
2915  {
2916  LWCOLLECTION *col = (LWCOLLECTION*)geom;
2917 
2918  for ( i = 0; i < col->ngeoms; i++ )
2919  {
2920  length += lwgeom_length_spheroid(col->geoms[i], s);
2921  }
2922  return length;
2923  }
2924 
2925  lwerror("unsupported type passed to lwgeom_length_sphere");
2926  return 0.0;
2927 }
#define LINETYPE
Definition: liblwgeom.h:61
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define TRIANGLETYPE
Definition: liblwgeom.h:73
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:2881
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM ** geoms
Definition: liblwgeom.h:465
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:2828
POINTARRAY ** rings
Definition: liblwgeom.h:413
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:955
int nrings
Definition: liblwgeom.h:411
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
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:1229

Here is the call graph for this function:

Here is the caller graph for this function: