PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_perimeter()

Datum geography_perimeter ( PG_FUNCTION_ARGS  )

Definition at line 566 of file geography_measurement.c.

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