PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum geography_dwithin_uncached ( PG_FUNCTION_ARGS  )

Definition at line 382 of file geography_measurement.c.

References SPHEROID::a, SPHEROID::b, distance(), error_if_srid_mismatch(), FALSE, gserialized_get_srid(), lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), SPHEROID::radius, and s.

383 {
384  LWGEOM *lwgeom1 = NULL;
385  LWGEOM *lwgeom2 = NULL;
386  GSERIALIZED *g1 = NULL;
387  GSERIALIZED *g2 = NULL;
388  double tolerance = 0.0;
389  double distance;
390  bool use_spheroid = true;
391  SPHEROID s;
392 
393  /* Get our geometry objects loaded into memory. */
394  g1 = PG_GETARG_GSERIALIZED_P(0);
395  g2 = PG_GETARG_GSERIALIZED_P(1);
396 
397  /* Read our tolerance value. */
398  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
399  tolerance = PG_GETARG_FLOAT8(2);
400 
401  /* Read our calculation type. */
402  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
403  use_spheroid = PG_GETARG_BOOL(3);
404 
406 
407  /* Initialize spheroid */
408  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
409 
410  /* Set to sphere if requested */
411  if ( ! use_spheroid )
412  s.a = s.b = s.radius;
413 
414  lwgeom1 = lwgeom_from_gserialized(g1);
415  lwgeom2 = lwgeom_from_gserialized(g2);
416 
417  /* Return FALSE on empty arguments. */
418  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
419  {
420  PG_RETURN_BOOL(FALSE);
421  }
422 
423  distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
424 
425  /* Clean up */
426  lwgeom_free(lwgeom1);
427  lwgeom_free(lwgeom2);
428  PG_FREE_IF_COPY(g1, 0);
429  PG_FREE_IF_COPY(g2, 1);
430 
431  /* Something went wrong... should already be eloged, return FALSE */
432  if ( distance < 0.0 )
433  {
434  elog(ERROR, "lwgeom_distance_spheroid returned negative!");
435  PG_RETURN_BOOL(FALSE);
436  }
437 
438  PG_RETURN_BOOL(distance <= tolerance);
439 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double b
Definition: liblwgeom.h:298
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
double radius
Definition: liblwgeom.h:302
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
char * s
Definition: cu_in_wkt.c:23
Datum distance(PG_FUNCTION_ARGS)
double a
Definition: liblwgeom.h:297
#define FALSE
Definition: dbfopen.c:168
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.
Definition: lwgeodetic.c:2081
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:69

Here is the call graph for this function: