PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_area()

Datum geography_area ( PG_FUNCTION_ARGS  )

Definition at line 501 of file geography_measurement.c.

502{
503 LWGEOM *lwgeom = NULL;
504 GSERIALIZED *g = NULL;
505 GBOX gbox;
506 double area;
507 bool use_spheroid = LW_TRUE;
508 SPHEROID s;
509
510 /* Get our geometry object loaded into memory. */
511 g = PG_GETARG_GSERIALIZED_P(0);
512
513 /* Read our calculation type */
514 use_spheroid = PG_GETARG_BOOL(1);
515
516 /* Initialize spheroid */
517 spheroid_init_from_srid(fcinfo, gserialized_get_srid(g), &s);
518
519 lwgeom = lwgeom_from_gserialized(g);
520
521 /* EMPTY things have no area */
522 if ( lwgeom_is_empty(lwgeom) )
523 {
524 lwgeom_free(lwgeom);
525 PG_RETURN_FLOAT8(0.0);
526 }
527
528 if ( lwgeom->bbox )
529 gbox = *(lwgeom->bbox);
530 else
531 lwgeom_calculate_gbox_geodetic(lwgeom, &gbox);
532
533#ifndef PROJ_GEODESIC
534 /* Test for cases that are currently not handled by spheroid code */
535 if ( use_spheroid )
536 {
537 /* We can't circle the poles right now */
538 if ( FP_GTEQ(gbox.zmax,1.0) || FP_LTEQ(gbox.zmin,-1.0) )
539 use_spheroid = LW_FALSE;
540 /* We can't cross the equator right now */
541 if ( gbox.zmax > 0.0 && gbox.zmin < 0.0 )
542 use_spheroid = LW_FALSE;
543 }
544#endif /* ifndef PROJ_GEODESIC */
545
546 /* User requests spherical calculation, turn our spheroid into a sphere */
547 if ( ! use_spheroid )
548 s.a = s.b = s.radius;
549
550 /* Calculate the area */
551 if ( use_spheroid )
552 area = lwgeom_area_spheroid(lwgeom, &s);
553 else
554 area = lwgeom_area_sphere(lwgeom, &s);
555
556 /* Clean up */
557 lwgeom_free(lwgeom);
558 PG_FREE_IF_COPY(g, 0);
559
560 /* Something went wrong... */
561 if ( area < 0.0 )
562 {
563 elog(ERROR, "lwgeom_area_spher(oid) returned area < 0.0");
564 PG_RETURN_NULL();
565 }
566
567 PG_RETURN_FLOAT8(area);
568}
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_FALSE
Definition liblwgeom.h:108
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition lwspheroid.c:647
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:107
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
#define FP_GTEQ(A, B)
#define FP_LTEQ(A, B)
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
double zmax
Definition liblwgeom.h:345
double zmin
Definition liblwgeom.h:344
GBOX * bbox
Definition liblwgeom.h:444

References LWGEOM::bbox, FP_GTEQ, FP_LTEQ, gserialized_get_srid(), LW_FALSE, LW_TRUE, lwgeom_area_sphere(), lwgeom_area_spheroid(), lwgeom_calculate_gbox_geodetic(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), s, GBOX::zmax, and GBOX::zmin.

Here is the call graph for this function: