PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ overlaps()

Datum overlaps ( PG_FUNCTION_ARGS  )

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

References contains(), error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, gbox_overlaps_2d(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), and POSTGIS2GEOS().

Referenced by isvaliddetail().

1929 {
1930  GSERIALIZED *geom1;
1931  GSERIALIZED *geom2;
1932  GEOSGeometry *g1, *g2;
1933  bool result;
1934  GBOX box1, box2;
1935 
1936  geom1 = PG_GETARG_GSERIALIZED_P(0);
1937  geom2 = PG_GETARG_GSERIALIZED_P(1);
1938 
1939  errorIfGeometryCollection(geom1,geom2);
1941 
1942  /* A.Overlaps(Empty) == FALSE */
1943  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1944  PG_RETURN_BOOL(false);
1945 
1946  /*
1947  * short-circuit 1: if geom2 bounding box does not overlap
1948  * geom1 bounding box we can prematurely return FALSE.
1949  * Do the test IFF BOUNDING BOX AVAILABLE.
1950  */
1951  if ( gserialized_get_gbox_p(geom1, &box1) &&
1952  gserialized_get_gbox_p(geom2, &box2) )
1953  {
1954  if ( ! gbox_overlaps_2d(&box1, &box2) )
1955  {
1956  PG_RETURN_BOOL(FALSE);
1957  }
1958  }
1959 
1960  initGEOS(lwpgnotice, lwgeom_geos_error);
1961 
1962  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
1963  if ( 0 == g1 ) /* exception thrown at construction */
1964  {
1965  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1966  PG_RETURN_NULL();
1967  }
1968 
1969  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1970 
1971  if ( 0 == g2 ) /* exception thrown at construction */
1972  {
1973  GEOSGeom_destroy(g1);
1974  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
1975  PG_RETURN_NULL();
1976  }
1977 
1978  result = GEOSOverlaps(g1,g2);
1979 
1980  GEOSGeom_destroy(g1);
1981  GEOSGeom_destroy(g2);
1982  if (result == 2)
1983  {
1984  HANDLE_GEOS_ERROR("GEOSOverlaps");
1985  PG_RETURN_NULL(); /* never get here */
1986  }
1987 
1988  PG_FREE_IF_COPY(geom1, 0);
1989  PG_FREE_IF_COPY(geom2, 1);
1990 
1991  PG_RETURN_BOOL(result);
1992 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:371
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
void lwgeom_geos_error(const char *fmt,...)
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:300
#define FALSE
Definition: dbfopen.c:168
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
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
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.
Here is the call graph for this function:
Here is the caller graph for this function: