PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_perimeter()

Datum geography_perimeter ( PG_FUNCTION_ARGS  )

Definition at line 563 of file geography_measurement.c.

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