PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_dwithin()

Datum geography_dwithin ( PG_FUNCTION_ARGS  )

Definition at line 275 of file geography_measurement.c.

276{
277 GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
278 GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
279 SPHEROID s;
280 double tolerance = 0.0;
281 bool use_spheroid = true;
282 double distance;
283 int dwithin = LW_FALSE;
284
285 gserialized_error_if_srid_mismatch(g1, g2, __func__);
286
287 /* Read our tolerance value. */
288 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
289 tolerance = PG_GETARG_FLOAT8(2);
290
291 /* Read our calculation type. */
292 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
293 use_spheroid = PG_GETARG_BOOL(3);
294
295 /* Initialize spheroid */
296 spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
297
298 /* Set to sphere if requested */
299 if ( ! use_spheroid )
300 s.a = s.b = s.radius;
301
302 /* Return FALSE on empty arguments. */
304 PG_RETURN_BOOL(false);
305
306 /* Do the brute force calculation if the cached calculation doesn't tick over */
307 if ( LW_FAILURE == geography_dwithin_cache(fcinfo, g1, g2, &s, tolerance, &dwithin) )
308 {
309 LWGEOM* lwgeom1 = lwgeom_from_gserialized(g1);
310 LWGEOM* lwgeom2 = lwgeom_from_gserialized(g2);
311 distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
312 /* Something went wrong... */
313 if ( distance < 0.0 )
314 elog(ERROR, "lwgeom_distance_spheroid returned negative!");
315 dwithin = (distance <= tolerance);
316 lwgeom_free(lwgeom1);
317 lwgeom_free(lwgeom2);
318 }
319
320 PG_FREE_IF_COPY(g1, 0);
321 PG_FREE_IF_COPY(g2, 1);
322 PG_RETURN_BOOL(dwithin);
323}
char * s
Definition cu_in_wkt.c:23
int geography_dwithin_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, int *dwithin)
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
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.
#define LW_FALSE
Definition liblwgeom.h:108
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
#define LW_FAILURE
Definition liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

References distance(), geography_dwithin_cache(), gserialized_error_if_srid_mismatch(), gserialized_get_srid(), gserialized_is_empty(), LW_FAILURE, LW_FALSE, lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_gserialized(), and s.

Referenced by geography_intersects().

Here is the call graph for this function:
Here is the caller graph for this function: