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

◆ 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 2688 of file postgis/lwgeom_geos.c.

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