PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ geography_perimeter()

Datum geography_perimeter ( PG_FUNCTION_ARGS  )

Definition at line 564 of file geography_measurement.c.

565 {
566  LWGEOM *lwgeom = NULL;
567  GSERIALIZED *g = NULL;
568  double length;
569  bool use_spheroid = LW_TRUE;
570  SPHEROID s;
571  int type;
572 
573  /* Get our geometry object loaded into memory. */
574  g = PG_GETARG_GSERIALIZED_P(0);
575 
576  /* Only return for area features. */
578  if ( ! (type == POLYGONTYPE || type == MULTIPOLYGONTYPE || type == COLLECTIONTYPE) )
579  {
580  PG_RETURN_FLOAT8(0.0);
581  }
582 
583  lwgeom = lwgeom_from_gserialized(g);
584 
585  /* EMPTY things have no perimeter */
586  if ( lwgeom_is_empty(lwgeom) )
587  {
588  lwgeom_free(lwgeom);
589  PG_RETURN_FLOAT8(0.0);
590  }
591 
592  /* Read our calculation type */
593  use_spheroid = PG_GETARG_BOOL(1);
594 
595  /* Initialize spheroid */
596  spheroid_init_from_srid(gserialized_get_srid(g), &s);
597 
598  /* User requests spherical calculation, turn our spheroid into a sphere */
599  if ( ! use_spheroid )
600  s.a = s.b = s.radius;
601 
602  /* Calculate the length */
603  length = lwgeom_length_spheroid(lwgeom, &s);
604 
605  /* Something went wrong... */
606  if ( length < 0.0 )
607  {
608  elog(ERROR, "lwgeom_length_spheroid returned length < 0.0");
609  PG_RETURN_NULL();
610  }
611 
612  /* Clean up, but not all the way to the point arrays */
613  lwgeom_free(lwgeom);
614 
615  PG_FREE_IF_COPY(g, 0);
616  PG_RETURN_FLOAT8(length);
617 }
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:123
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:122
#define POLYGONTYPE
Definition: liblwgeom.h:119
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3137
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
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: