PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_dfullywithin()

Datum LWGEOM_dfullywithin ( PG_FUNCTION_ARGS  )

Returns boolean true if the second argument is fully contained in a buffer of the first argument.

Definition at line 2687 of file postgis/lwgeom_geos.c.

2688 {
2689  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
2690  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
2691  LWGEOM *lwg1 = lwgeom_from_gserialized(geom1);
2692  LWGEOM *lwg2 = lwgeom_from_gserialized(geom2);
2693  double radius = PG_GETARG_FLOAT8(2);
2694  GEOSGeometry *buffer1 = NULL;
2695  GEOSGeometry *geos1 = NULL, *geos2 = NULL;
2696  char contained;
2697 
2698  if (radius < 0.0)
2699  {
2700  elog(ERROR, "Tolerance cannot be less than zero\n");
2701  PG_RETURN_NULL();
2702  }
2703 
2704  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
2705 
2706  if (lwgeom_is_empty(lwg1) || lwgeom_is_empty(lwg2))
2707  PG_RETURN_BOOL(false);
2708 
2709  if (!(lwgeom_isfinite(lwg1) && lwgeom_isfinite(lwg2)))
2710  PG_RETURN_BOOL(false);
2711 
2712  initGEOS(lwpgnotice, lwgeom_geos_error);
2713 
2714  geos1 = LWGEOM2GEOS(lwg1, true);
2715  geos2 = LWGEOM2GEOS(lwg2, true);
2716  lwgeom_free(lwg1);
2717  lwgeom_free(lwg2);
2718  if (!(geos1 && geos2))
2719  HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
2720 
2721  buffer1 = GEOSBuffer(geos1, radius, 16);
2722  GEOSGeom_destroy(geos1);
2723  if (!(buffer1))
2724  HANDLE_GEOS_ERROR("Buffer operation failed");
2725 
2726  contained = GEOSCovers(buffer1, geos2);
2727  GEOSGeom_destroy(buffer1);
2728  GEOSGeom_destroy(geos2);
2729 
2730  if (contained == 2) HANDLE_GEOS_ERROR("GEOSContains");
2731 
2732  PG_FREE_IF_COPY(geom1, 0);
2733  PG_FREE_IF_COPY(geom2, 1);
2734 
2735  PG_RETURN_BOOL(contained == 1);
2736 }
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:432
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2807
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
#define HANDLE_GEOS_ERROR(label)

References gserialized_error_if_srid_mismatch(), HANDLE_GEOS_ERROR, LWGEOM2GEOS(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_geos_error(), lwgeom_is_empty(), and lwgeom_isfinite().

Here is the call graph for this function: