PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_dwithin()

Datum LWGEOM_dwithin ( PG_FUNCTION_ARGS  )

Definition at line 729 of file lwgeom_functions_basic.c.

730 {
731  double mindist;
732  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
733  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
734  double tolerance = PG_GETARG_FLOAT8(2);
735  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
736  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
737 
738  if (tolerance < 0)
739  {
740  elog(ERROR, "Tolerance cannot be less than zero\n");
741  PG_RETURN_NULL();
742  }
743 
744  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
745 
746  if (lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2))
747  {
748  PG_RETURN_BOOL(false);
749  }
750 
751  mindist = lwgeom_mindistance2d_tolerance(lwgeom1, lwgeom2, tolerance);
752 
753  PG_FREE_IF_COPY(geom1, 0);
754  PG_FREE_IF_COPY(geom2, 1);
755  /*empty geometries cases should be right handled since return from underlying
756  functions should be FLT_MAX which causes false as answer*/
757  PG_RETURN_BOOL(tolerance >= mindist);
758 }
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:403
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:210
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

References gserialized_error_if_srid_mismatch(), lwgeom_from_gserialized(), lwgeom_is_empty(), and lwgeom_mindistance2d_tolerance().

Here is the call graph for this function: