PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_length_spheroid()

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 3281 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, ovdump::type, and LWGEOM::type.

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

3282 {
3283  int type;
3284  int i = 0;
3285  double length = 0.0;
3286 
3287  assert(geom);
3288 
3289  /* No area in nothing */
3290  if ( lwgeom_is_empty(geom) )
3291  return 0.0;
3292 
3293  type = geom->type;
3294 
3295  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
3296  return 0.0;
3297 
3298  if ( type == LINETYPE )
3299  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
3300 
3301  if ( type == POLYGONTYPE )
3302  {
3303  LWPOLY *poly = (LWPOLY*)geom;
3304  for ( i = 0; i < poly->nrings; i++ )
3305  {
3306  length += ptarray_length_spheroid(poly->rings[i], s);
3307  }
3308  return length;
3309  }
3310 
3311  if ( type == TRIANGLETYPE )
3312  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
3313 
3314  if ( lwtype_is_collection( type ) )
3315  {
3316  LWCOLLECTION *col = (LWCOLLECTION*)geom;
3317 
3318  for ( i = 0; i < col->ngeoms; i++ )
3319  {
3320  length += lwgeom_length_spheroid(col->geoms[i], s);
3321  }
3322  return length;
3323  }
3324 
3325  lwerror("unsupported type passed to lwgeom_length_sphere");
3326  return 0.0;
3327 }
#define LINETYPE
Definition: liblwgeom.h:86
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define TRIANGLETYPE
Definition: liblwgeom.h:98
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3281
LWGEOM ** geoms
Definition: liblwgeom.h:509
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:3228
POINTARRAY ** rings
Definition: liblwgeom.h:457
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1048
int nrings
Definition: liblwgeom.h:455
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
type
Definition: ovdump.py:41
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:1346
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: