PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ geography_perimeter()

Datum geography_perimeter ( PG_FUNCTION_ARGS  )

Definition at line 567 of file geography_measurement.c.

568 {
569  LWGEOM *lwgeom = NULL;
570  GSERIALIZED *g = NULL;
571  double length;
572  bool use_spheroid = LW_TRUE;
573  SPHEROID s;
574  int type;
575 
576  /* Get our geometry object loaded into memory. */
577  g = PG_GETARG_GSERIALIZED_P(0);
578 
579  /* Only return for area features. */
581  if ( ! (type == POLYGONTYPE || type == MULTIPOLYGONTYPE || type == COLLECTIONTYPE) )
582  {
583  PG_RETURN_FLOAT8(0.0);
584  }
585 
586  lwgeom = lwgeom_from_gserialized(g);
587 
588  /* EMPTY things have no perimeter */
589  if ( lwgeom_is_empty(lwgeom) )
590  {
591  lwgeom_free(lwgeom);
592  PG_RETURN_FLOAT8(0.0);
593  }
594 
595  /* Read our calculation type */
596  use_spheroid = PG_GETARG_BOOL(1);
597 
598  /* Initialize spheroid */
599  spheroid_init_from_srid(gserialized_get_srid(g), &s);
600 
601  /* User requests spherical calculation, turn our spheroid into a sphere */
602  if ( ! use_spheroid )
603  s.a = s.b = s.radius;
604 
605  /* Calculate the length */
606  length = lwgeom_length_spheroid(lwgeom, &s);
607 
608  /* Something went wrong... */
609  if ( length < 0.0 )
610  {
611  elog(ERROR, "lwgeom_length_spheroid returned length < 0.0");
612  PG_RETURN_NULL();
613  }
614 
615  /* Clean up, but not all the way to the point arrays */
616  lwgeom_free(lwgeom);
617 
618  PG_FREE_IF_COPY(g, 0);
619  PG_RETURN_FLOAT8(length);
620 }
char * s
Definition: cu_in_wkt.c:23
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
#define POLYGONTYPE
Definition: liblwgeom.h:118
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3287
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
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

References COLLECTIONTYPE, gserialized_get_srid(), gserialized_get_type(), LW_TRUE, lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwgeom_length_spheroid(), MULTIPOLYGONTYPE, POLYGONTYPE, s, and ovdump::type.

Here is the call graph for this function: