PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ geography_perimeter()

Datum geography_perimeter ( PG_FUNCTION_ARGS  )

Definition at line 575 of file geography_measurement.c.

576 {
577  LWGEOM *lwgeom = NULL;
578  GSERIALIZED *g = NULL;
579  double length;
580  bool use_spheroid = LW_TRUE;
581  SPHEROID s;
582  int type;
583 
584  /* Get our geometry object loaded into memory. */
585  g = PG_GETARG_GSERIALIZED_P(0);
586 
587  /* Only return for area features. */
589  if ( ! (type == POLYGONTYPE || type == MULTIPOLYGONTYPE || type == COLLECTIONTYPE) )
590  {
591  PG_RETURN_FLOAT8(0.0);
592  }
593 
594  lwgeom = lwgeom_from_gserialized(g);
595 
596  /* EMPTY things have no perimeter */
597  if ( lwgeom_is_empty(lwgeom) )
598  {
599  lwgeom_free(lwgeom);
600  PG_RETURN_FLOAT8(0.0);
601  }
602 
603  /* Read our calculation type */
604  use_spheroid = PG_GETARG_BOOL(1);
605 
606  /* Initialize spheroid */
607  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g), &s);
608 
609  /* User requests spherical calculation, turn our spheroid into a sphere */
610  if ( ! use_spheroid )
611  s.a = s.b = s.radius;
612 
613  /* Calculate the length */
614  length = lwgeom_length_spheroid(lwgeom, &s);
615 
616  /* Something went wrong... */
617  if ( length < 0.0 )
618  {
619  elog(ERROR, "lwgeom_length_spheroid returned length < 0.0");
620  PG_RETURN_NULL();
621  }
622 
623  /* Clean up, but not all the way to the point arrays */
624  lwgeom_free(lwgeom);
625 
626  PG_FREE_IF_COPY(g, 0);
627  PG_RETURN_FLOAT8(length);
628 }
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:3297
#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:193
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: