PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geography_from_geometry()

Datum geography_from_geometry ( PG_FUNCTION_ARGS  )

Definition at line 608 of file geography_inout.c.

609 {
610  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
611  LWGEOM *lwgeom = NULL;
612  GSERIALIZED *g_ser = NULL;
613 
615 
616  lwgeom = lwgeom_from_gserialized(geom);
617 
618  /* Force default SRID */
619  if ( (int)lwgeom->srid <= 0 )
620  {
621  lwgeom->srid = SRID_DEFAULT;
622  }
623 
624  /* Error on any SRID != default */
625  srid_is_latlong(fcinfo, lwgeom->srid);
626 
627  /* Force the geometry to have valid geodetic coordinate range. */
628  lwgeom_nudge_geodetic(lwgeom);
629  if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
630  {
631  ereport(NOTICE, (
632  errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
633  );
634  }
635 
636  /* force recalculate of box by dropping */
637  lwgeom_drop_bbox(lwgeom);
638 
639  lwgeom_set_geodetic(lwgeom, true);
640  /* We are trusting geography_serialize will add a box if needed */
641  g_ser = geography_serialize(lwgeom);
642 
643 
644  lwgeom_free(lwgeom);
645 
646  PG_FREE_IF_COPY(geom, 0);
647  PG_RETURN_POINTER(g_ser);
648 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
void geography_valid_type(uint8_t type)
The geography type only support POINT, LINESTRING, POLYGON, MULTI* variants of same,...
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:952
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:673
#define SRID_DEFAULT
Definition: liblwgeom.h:198
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3222
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3404
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int32_t srid
Definition: liblwgeom.h:402

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

Here is the call graph for this function: