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

◆ geography_from_geometry()

Datum geography_from_geometry ( PG_FUNCTION_ARGS  )

Definition at line 489 of file geography_inout.c.

490{
491 GSERIALIZED *g_ser = NULL;
492 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
493 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
494
496
497 /* Force default SRID */
498 if ( (int)lwgeom->srid <= 0 )
499 {
500 lwgeom->srid = SRID_DEFAULT;
501 }
502
503 /* Error on any SRID != default */
504 srid_check_latlong(lwgeom->srid);
505
506 /* Force the geometry to have valid geodetic coordinate range. */
507 lwgeom_nudge_geodetic(lwgeom);
508 if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
509 {
510 ereport(NOTICE, (
511 errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
512 );
513 }
514
515 /* force recalculate of box by dropping */
516 lwgeom_drop_bbox(lwgeom);
517
518 lwgeom_set_geodetic(lwgeom, true);
519 /* We are trusting geography_serialize will add a box if needed */
520 g_ser = geography_serialize(lwgeom);
521
522
523 lwgeom_free(lwgeom);
524
525 PG_FREE_IF_COPY(geom, 0);
526 PG_RETURN_POINTER(g_ser);
527}
void geography_valid_type(uint8_t type)
The geography type only support POINT, LINESTRING, POLYGON, MULTI* variants of same,...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition lwgeom.c:992
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition lwgeom.c:710
#define SRID_DEFAULT
Definition liblwgeom.h:225
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition lwinline.h:141
int32_t srid
Definition liblwgeom.h:460

References geography_valid_type(), LW_TRUE, lwgeom_drop_bbox(), lwgeom_force_geodetic(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_get_type(), lwgeom_nudge_geodetic(), lwgeom_set_geodetic(), LWGEOM::srid, and SRID_DEFAULT.

Here is the call graph for this function: