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

◆ geography_dwithin_uncached()

Datum geography_dwithin_uncached ( PG_FUNCTION_ARGS  )

Definition at line 395 of file geography_measurement.c.

396{
397 LWGEOM *lwgeom1 = NULL;
398 LWGEOM *lwgeom2 = NULL;
399 GSERIALIZED *g1 = NULL;
400 GSERIALIZED *g2 = NULL;
401 double tolerance = 0.0;
402 double distance;
403 bool use_spheroid = true;
404 SPHEROID s;
405
406 /* Get our geometry objects loaded into memory. */
407 g1 = PG_GETARG_GSERIALIZED_P(0);
408 g2 = PG_GETARG_GSERIALIZED_P(1);
409 gserialized_error_if_srid_mismatch(g1, g2, __func__);
410
411 /* Read our tolerance value. */
412 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
413 tolerance = PG_GETARG_FLOAT8(2);
414
415 /* Read our calculation type. */
416 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
417 use_spheroid = PG_GETARG_BOOL(3);
418
419 /* Initialize spheroid */
420 spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
421
422 /* Set to sphere if requested */
423 if ( ! use_spheroid )
424 s.a = s.b = s.radius;
425
426 lwgeom1 = lwgeom_from_gserialized(g1);
427 lwgeom2 = lwgeom_from_gserialized(g2);
428
429 /* Return FALSE on empty arguments. */
430 if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
431 {
432 PG_RETURN_BOOL(false);
433 }
434
435 distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
436
437 /* Clean up */
438 lwgeom_free(lwgeom1);
439 lwgeom_free(lwgeom2);
440 PG_FREE_IF_COPY(g1, 0);
441 PG_FREE_IF_COPY(g2, 1);
442
443 /* Something went wrong... should already be eloged, return FALSE */
444 if ( distance < 0.0 )
445 {
446 elog(ERROR, "lwgeom_distance_spheroid returned negative!");
447 PG_RETURN_BOOL(false);
448 }
449
450 PG_RETURN_BOOL(distance <= tolerance);
451}
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:1138
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:193
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: