PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ geography_from_geometry()

Datum geography_from_geometry ( PG_FUNCTION_ARGS  )

Definition at line 573 of file geography_inout.c.

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

Referenced by geography_from_binary().

574 {
575  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
576  LWGEOM *lwgeom = NULL;
577  GSERIALIZED *g_ser = NULL;
578 
580 
581  lwgeom = lwgeom_from_gserialized(geom);
582 
583  /* Force default SRID */
584  if ( (int)lwgeom->srid <= 0 )
585  {
586  lwgeom->srid = SRID_DEFAULT;
587  }
588 
589  /* Error on any SRID != default */
590  srid_is_latlong(fcinfo, lwgeom->srid);
591 
592  /* Force the geometry to have valid geodetic coordinate range. */
593  lwgeom_nudge_geodetic(lwgeom);
594  if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
595  {
596  ereport(NOTICE, (
597  errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
598  );
599  }
600 
601  /*
602  ** Serialize our lwgeom and set the geodetic flag so subsequent
603  ** functions do the right thing.
604  */
605  lwgeom_set_geodetic(lwgeom, true);
606 
607  /* Recalculate the boxes after re-setting the geodetic bit */
608  lwgeom_drop_bbox(lwgeom);
609  lwgeom_add_bbox(lwgeom);
610 
611  g_ser = geography_serialize(lwgeom);
612 
613  /*
614  ** Replace the unaligned lwgeom with a new aligned one based on GSERIALIZED.
615  */
616  lwgeom_free(lwgeom);
617 
618  PG_FREE_IF_COPY(geom, 0);
619  PG_RETURN_POINTER(g_ser);
620 
621 }
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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define SRID_DEFAULT
Definition: liblwgeom.h:179
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:2991
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:586
int32_t srid
Definition: liblwgeom.h:383
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:2809
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:858
void geography_valid_type(uint8_t type)
The geography type only support POINT, LINESTRING, POLYGON, MULTI* variants of same, and GEOMETRYCOLLECTION.
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
Here is the call graph for this function:
Here is the caller graph for this function: