PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum overlaps ( PG_FUNCTION_ARGS  )

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, gbox_overlaps_2d(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), LW_FALSE, lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), and result.

1927 {
1928  GSERIALIZED *geom1;
1929  GSERIALIZED *geom2;
1930  GEOSGeometry *g1, *g2;
1931  bool result;
1932  GBOX box1, box2;
1933 
1934  geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1935  geom2 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
1936 
1937  errorIfGeometryCollection(geom1,geom2);
1939 
1940  /* A.Overlaps(Empty) == FALSE */
1941  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1942  PG_RETURN_BOOL(false);
1943 
1944  /*
1945  * short-circuit 1: if geom2 bounding box does not overlap
1946  * geom1 bounding box we can prematurely return FALSE.
1947  * Do the test IFF BOUNDING BOX AVAILABLE.
1948  */
1949  if ( gserialized_get_gbox_p(geom1, &box1) &&
1950  gserialized_get_gbox_p(geom2, &box2) )
1951  {
1952  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
1953  {
1954  PG_RETURN_BOOL(FALSE);
1955  }
1956  }
1957 
1958  initGEOS(lwnotice, lwgeom_geos_error);
1959 
1960  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
1961  if ( 0 == g1 ) /* exception thrown at construction */
1962  {
1963  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1964  PG_RETURN_NULL();
1965  }
1966 
1967  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1968 
1969  if ( 0 == g2 ) /* exception thrown at construction */
1970  {
1971  GEOSGeom_destroy(g1);
1972  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1973  PG_RETURN_NULL();
1974  }
1975 
1976  result = GEOSOverlaps(g1,g2);
1977 
1978  GEOSGeom_destroy(g1);
1979  GEOSGeom_destroy(g2);
1980  if (result == 2)
1981  {
1982  lwerror("GEOSOverlaps: %s", lwgeom_geos_errmsg);
1983  PG_RETURN_NULL(); /* never get here */
1984  }
1985 
1986  PG_FREE_IF_COPY(geom1, 0);
1987  PG_FREE_IF_COPY(geom2, 1);
1988 
1989  PG_RETURN_BOOL(result);
1990 }
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:373
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:52
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:281
#define FALSE
Definition: dbfopen.c:169
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
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:70
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: