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

Definition at line 968 of file geography_measurement.c.

References gserialized_get_type(), gserialized_is_empty(), lwgeom_add_bbox(), lwgeom_drop_bbox(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_segmentize_sphere(), lwgeom_set_geodetic(), MULTIPOINTTYPE, POINTTYPE, and WGS84_RADIUS.

969 {
970  LWGEOM *lwgeom1 = NULL;
971  LWGEOM *lwgeom2 = NULL;
972  GSERIALIZED *g1 = NULL;
973  GSERIALIZED *g2 = NULL;
974  double max_seg_length;
975  uint32_t type1;
976 
977  /* Get our geometry object loaded into memory. */
978  g1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
979  type1 = gserialized_get_type(g1);
980 
981  /* Convert max_seg_length from metric units to radians */
982  max_seg_length = PG_GETARG_FLOAT8(1) / WGS84_RADIUS;
983 
984  /* We can't densify points or points, reflect them back */
985  if ( type1 == POINTTYPE || type1 == MULTIPOINTTYPE || gserialized_is_empty(g1) )
986  PG_RETURN_POINTER(g1);
987 
988  /* Deserialize */
989  lwgeom1 = lwgeom_from_gserialized(g1);
990 
991  /* Calculate the densified geometry */
992  lwgeom2 = lwgeom_segmentize_sphere(lwgeom1, max_seg_length);
993 
994  /*
995  ** Set the geodetic flag so subsequent
996  ** functions do the right thing.
997  */
998  lwgeom_set_geodetic(lwgeom2, true);
999 
1000  /* Recalculate the boxes after re-setting the geodetic bit */
1001  lwgeom_drop_bbox(lwgeom2);
1002  lwgeom_add_bbox(lwgeom2);
1003 
1004  g2 = geography_serialize(lwgeom2);
1005 
1006  /* Clean up */
1007  lwgeom_free(lwgeom1);
1008  lwgeom_free(lwgeom2);
1009  PG_FREE_IF_COPY(g1, 0);
1010 
1011  PG_RETURN_POINTER(g2);
1012 }
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.
#define WGS84_RADIUS
Definition: liblwgeom.h:98
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:542
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
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
LWGEOM * lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length)
Derive a new geometry with vertices added to ensure no vertex is more than max_seg_length (in radians...
Definition: lwgeodetic.c:1638
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
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: