PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geography_from_geometry ( PG_FUNCTION_ARGS  )

Definition at line 568 of file geography_inout.c.

References geography_valid_type(), 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(), LWGEOM::srid, and SRID_DEFAULT.

569 {
570  GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
571  LWGEOM *lwgeom = NULL;
572  GSERIALIZED *g_ser = NULL;
573 
575 
576  lwgeom = lwgeom_from_gserialized(geom);
577 
578  /* Force default SRID */
579  if ( (int)lwgeom->srid <= 0 )
580  {
581  lwgeom->srid = SRID_DEFAULT;
582  }
583 
584  /* Error on any SRID != default */
585  srid_is_latlong(fcinfo, lwgeom->srid);
586 
587  /* Force the geometry to have valid geodetic coordinate range. */
588  lwgeom_nudge_geodetic(lwgeom);
589  if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
590  {
591  ereport(NOTICE, (
592  errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
593  );
594  }
595 
596  /*
597  ** Serialize our lwgeom and set the geodetic flag so subsequent
598  ** functions do the right thing.
599  */
600  lwgeom_set_geodetic(lwgeom, true);
601 
602  /* Recalculate the boxes after re-setting the geodetic bit */
603  lwgeom_drop_bbox(lwgeom);
604  lwgeom_add_bbox(lwgeom);
605 
606  g_ser = geography_serialize(lwgeom);
607 
608  /*
609  ** Replace the unaligned lwgeom with a new aligned one based on GSERIALIZED.
610  */
611  lwgeom_free(lwgeom);
612 
613  PG_FREE_IF_COPY(geom, 0);
614  PG_RETURN_POINTER(g_ser);
615 
616 }
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define SRID_DEFAULT
Definition: liblwgeom.h:161
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:2988
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:542
int32_t srid
Definition: liblwgeom.h:355
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:2806
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:814
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:555

Here is the call graph for this function: