PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geography_segmentize()

Datum geography_segmentize ( PG_FUNCTION_ARGS  )

Definition at line 1074 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().

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