PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geography_segmentize()

Datum geography_segmentize ( PG_FUNCTION_ARGS  )

Definition at line 1070 of file geography_measurement.c.

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

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.

Here is the call graph for this function: