PostGIS  2.5.0dev-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 3196 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().

3197 {
3198  int type;
3199  uint32_t i = 0;
3200  double length = 0.0;
3201 
3202  assert(geom);
3203 
3204  /* No area in nothing */
3205  if ( lwgeom_is_empty(geom) )
3206  return 0.0;
3207 
3208  type = geom->type;
3209 
3210  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
3211  return 0.0;
3212 
3213  if ( type == LINETYPE )
3214  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
3215 
3216  if ( type == POLYGONTYPE )
3217  {
3218  LWPOLY *poly = (LWPOLY*)geom;
3219  for ( i = 0; i < poly->nrings; i++ )
3220  {
3221  length += ptarray_length_spheroid(poly->rings[i], s);
3222  }
3223  return length;
3224  }
3225 
3226  if ( type == TRIANGLETYPE )
3227  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
3228 
3229  if ( lwtype_is_collection( type ) )
3230  {
3231  LWCOLLECTION *col = (LWCOLLECTION*)geom;
3232 
3233  for ( i = 0; i < col->ngeoms; i++ )
3234  {
3235  length += lwgeom_length_spheroid(col->geoms[i], s);
3236  }
3237  return length;
3238  }
3239 
3240  lwerror("unsupported type passed to lwgeom_length_sphere");
3241  return 0.0;
3242 }
#define LINETYPE
Definition: liblwgeom.h:85
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define TRIANGLETYPE
Definition: liblwgeom.h:97
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3196
uint32_t ngeoms
Definition: liblwgeom.h:506
uint32_t nrings
Definition: liblwgeom.h:454
unsigned int uint32_t
Definition: uthash.h:78
LWGEOM ** geoms
Definition: liblwgeom.h:508
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:3143
POINTARRAY ** rings
Definition: liblwgeom.h:456
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1086
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
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:1386
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

Here is the call graph for this function:

Here is the caller graph for this function: