PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ geography_dwithin_uncached()

Datum geography_dwithin_uncached ( PG_FUNCTION_ARGS  )

Definition at line 387 of file geography_measurement.c.

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