PostGIS  3.0.6dev-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 3297 of file lwgeodetic.c.

3298 {
3299  int type;
3300  uint32_t i = 0;
3301  double length = 0.0;
3302 
3303  assert(geom);
3304 
3305  /* No area in nothing */
3306  if ( lwgeom_is_empty(geom) )
3307  return 0.0;
3308 
3309  type = geom->type;
3310 
3311  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
3312  return 0.0;
3313 
3314  if ( type == LINETYPE )
3315  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
3316 
3317  if ( type == POLYGONTYPE )
3318  {
3319  LWPOLY *poly = (LWPOLY*)geom;
3320  for ( i = 0; i < poly->nrings; i++ )
3321  {
3322  length += ptarray_length_spheroid(poly->rings[i], s);
3323  }
3324  return length;
3325  }
3326 
3327  if ( type == TRIANGLETYPE )
3328  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
3329 
3330  if ( lwtype_is_collection( type ) )
3331  {
3332  LWCOLLECTION *col = (LWCOLLECTION*)geom;
3333 
3334  for ( i = 0; i < col->ngeoms; i++ )
3335  {
3336  length += lwgeom_length_spheroid(col->geoms[i], s);
3337  }
3338  return length;
3339  }
3340 
3341  lwerror("unsupported type passed to lwgeom_length_sphere");
3342  return 0.0;
3343 }
char * s
Definition: cu_in_wkt.c:23
#define LINETYPE
Definition: liblwgeom.h:117
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1087
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define POLYGONTYPE
Definition: liblwgeom.h:118
#define TRIANGLETYPE
Definition: liblwgeom.h:129
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:3244
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3297
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:193
type
Definition: ovdump.py:42
uint32_t ngeoms
Definition: liblwgeom.h:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
uint8_t type
Definition: liblwgeom.h:448
POINTARRAY ** rings
Definition: liblwgeom.h:505
uint32_t nrings
Definition: liblwgeom.h:510

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

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

Here is the call graph for this function:
Here is the caller graph for this function: