PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ geography_segmentize()

Datum geography_segmentize ( PG_FUNCTION_ARGS  )

Definition at line 1066 of file geography_measurement.c.

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

Referenced by geography_azimuth().

1067 {
1068  LWGEOM *lwgeom1 = NULL;
1069  LWGEOM *lwgeom2 = NULL;
1070  GSERIALIZED *g1 = NULL;
1071  GSERIALIZED *g2 = NULL;
1072  double max_seg_length;
1073  uint32_t type1;
1074 
1075  /* Get our geometry object loaded into memory. */
1076  g1 = PG_GETARG_GSERIALIZED_P(0);
1077  type1 = gserialized_get_type(g1);
1078 
1079  /* Convert max_seg_length from metric units to radians */
1080  max_seg_length = PG_GETARG_FLOAT8(1) / WGS84_RADIUS;
1081 
1082  /* We can't densify points or points, reflect them back */
1083  if ( type1 == POINTTYPE || type1 == MULTIPOINTTYPE || gserialized_is_empty(g1) )
1084  PG_RETURN_POINTER(g1);
1085 
1086  /* Deserialize */
1087  lwgeom1 = lwgeom_from_gserialized(g1);
1088 
1089  /* Calculate the densified geometry */
1090  lwgeom2 = lwgeom_segmentize_sphere(lwgeom1, max_seg_length);
1091 
1092  /*
1093  ** Set the geodetic flag so subsequent
1094  ** functions do the right thing.
1095  */
1096  lwgeom_set_geodetic(lwgeom2, true);
1097 
1098  /* Recalculate the boxes after re-setting the geodetic bit */
1099  lwgeom_drop_bbox(lwgeom2);
1100 
1101  /* We are trusting geography_serialize will add a box if needed */
1102  g2 = geography_serialize(lwgeom2);
1103 
1104  /* Clean up */
1105  lwgeom_free(lwgeom1);
1106  lwgeom_free(lwgeom2);
1107  PG_FREE_IF_COPY(g1, 0);
1108 
1109  PG_RETURN_POINTER(g2);
1110 }
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
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define WGS84_RADIUS
Definition: liblwgeom.h:130
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:673
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
unsigned int uint32_t
Definition: uthash.h:78
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
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:1656
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
Here is the call graph for this function:
Here is the caller graph for this function: