PostGIS  2.3.7dev-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 2895 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().

2896 {
2897  int type;
2898  int i = 0;
2899  double length = 0.0;
2900 
2901  assert(geom);
2902 
2903  /* No area in nothing */
2904  if ( lwgeom_is_empty(geom) )
2905  return 0.0;
2906 
2907  type = geom->type;
2908 
2909  if ( type == POINTTYPE || type == MULTIPOINTTYPE )
2910  return 0.0;
2911 
2912  if ( type == LINETYPE )
2913  return ptarray_length_spheroid(((LWLINE*)geom)->points, s);
2914 
2915  if ( type == POLYGONTYPE )
2916  {
2917  LWPOLY *poly = (LWPOLY*)geom;
2918  for ( i = 0; i < poly->nrings; i++ )
2919  {
2920  length += ptarray_length_spheroid(poly->rings[i], s);
2921  }
2922  return length;
2923  }
2924 
2925  if ( type == TRIANGLETYPE )
2926  return ptarray_length_spheroid(((LWTRIANGLE*)geom)->points, s);
2927 
2928  if ( lwtype_is_collection( type ) )
2929  {
2930  LWCOLLECTION *col = (LWCOLLECTION*)geom;
2931 
2932  for ( i = 0; i < col->ngeoms; i++ )
2933  {
2934  length += lwgeom_length_spheroid(col->geoms[i], s);
2935  }
2936  return length;
2937  }
2938 
2939  lwerror("unsupported type passed to lwgeom_length_sphere");
2940  return 0.0;
2941 }
#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:2895
LWGEOM ** geoms
Definition: liblwgeom.h:508
double ptarray_length_spheroid(const POINTARRAY *pa, const SPHEROID *s)
Definition: lwgeodetic.c:2842
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:1012
int nrings
Definition: liblwgeom.h:454
#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:1310
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102

Here is the call graph for this function:

Here is the caller graph for this function: