PostGIS  3.4.0dev-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 3296 of file lwgeodetic.c.

3297 {
3298  int type;
3299  uint32_t i = 0;
3300  double length = 0.0;
3301 
3302  assert(geom);
3303 
3304  /* No area in nothing */
3305  if ( lwgeom_is_empty(geom) )
3306  return 0.0;
3307 
3308  type = geom->type;
3309 
3310  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
3311  return 0.0;
3312 
3313  if ( type == LINETYPE )
3314  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
3315 
3316  if ( type == POLYGONTYPE )
3317  {
3318  LWPOLY *poly = (LWPOLY*)geom;
3319  for ( i = 0; i < poly->nrings; i++ )
3320  {
3321  length += ptarray_length_spheroid(poly->rings[i], s);
3322  }
3323  return length;
3324  }
3325 
3326  if ( type == TRIANGLETYPE )
3327  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
3328 
3329  if ( lwtype_is_collection( type ) )
3330  {
3331  LWCOLLECTION *col = (LWCOLLECTION*)geom;
3332 
3333  for ( i = 0; i < col->ngeoms; i++ )
3334  {
3335  length += lwgeom_length_spheroid(col->geoms[i], s);
3336  }
3337  return length;
3338  }
3339 
3340  lwerror("unsupported type passed to lwgeom_length_sphere");
3341  return 0.0;
3342 }
char * s
Definition: cu_in_wkt.c:23
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define TRIANGLETYPE
Definition: liblwgeom.h:115
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:3243
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3296
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:203
type
Definition: ovdump.py:42
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462
POINTARRAY ** rings
Definition: liblwgeom.h:519
uint32_t nrings
Definition: liblwgeom.h:524

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: