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

◆ geography_dwithin_uncached()

Datum geography_dwithin_uncached ( PG_FUNCTION_ARGS  )

Definition at line 386 of file geography_measurement.c.

387{
388 LWGEOM *lwgeom1 = NULL;
389 LWGEOM *lwgeom2 = NULL;
390 GSERIALIZED *g1 = NULL;
391 GSERIALIZED *g2 = NULL;
392 double tolerance = 0.0;
393 double distance;
394 bool use_spheroid = true;
395 SPHEROID s;
396
397 /* Get our geometry objects loaded into memory. */
398 g1 = PG_GETARG_GSERIALIZED_P(0);
399 g2 = PG_GETARG_GSERIALIZED_P(1);
400 gserialized_error_if_srid_mismatch(g1, g2, __func__);
401
402 /* Read our tolerance value. */
403 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
404 tolerance = PG_GETARG_FLOAT8(2);
405
406 /* Read our calculation type. */
407 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
408 use_spheroid = PG_GETARG_BOOL(3);
409
410 /* Initialize spheroid */
411 spheroid_init_from_srid(gserialized_get_srid(g1), &s);
412
413 /* Set to sphere if requested */
414 if ( ! use_spheroid )
415 s.a = s.b = s.radius;
416
417 lwgeom1 = lwgeom_from_gserialized(g1);
418 lwgeom2 = lwgeom_from_gserialized(g2);
419
420 /* Return FALSE on empty arguments. */
421 if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
422 {
423 PG_RETURN_BOOL(false);
424 }
425
426 distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
427
428 /* Clean up */
429 lwgeom_free(lwgeom1);
430 lwgeom_free(lwgeom2);
431 PG_FREE_IF_COPY(g1, 0);
432 PG_FREE_IF_COPY(g2, 1);
433
434 /* Something went wrong... should already be eloged, return FALSE */
435 if ( distance < 0.0 )
436 {
437 elog(ERROR, "lwgeom_distance_spheroid returned negative!");
438 PG_RETURN_BOOL(false);
439 }
440
441 PG_RETURN_BOOL(distance <= tolerance);
442}
char * s
Definition cu_in_wkt.c:23
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.
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.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

References distance(), gserialized_error_if_srid_mismatch(), gserialized_get_srid(), lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), and s.

Here is the call graph for this function: