PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ overlaps()

Datum overlaps ( PG_FUNCTION_ARGS  )

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

1566 {
1567  GSERIALIZED *geom1;
1568  GSERIALIZED *geom2;
1569  GEOSGeometry *g1, *g2;
1570  char result;
1571  GBOX box1, box2;
1572 
1573  geom1 = PG_GETARG_GSERIALIZED_P(0);
1574  geom2 = PG_GETARG_GSERIALIZED_P(1);
1575 
1576  errorIfGeometryCollection(geom1,geom2);
1578 
1579  /* A.Overlaps(Empty) == FALSE */
1580  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1581  PG_RETURN_BOOL(false);
1582 
1583  /*
1584  * short-circuit 1: if geom2 bounding box does not overlap
1585  * geom1 bounding box we can return FALSE.
1586  */
1587  if ( gserialized_get_gbox_p(geom1, &box1) &&
1588  gserialized_get_gbox_p(geom2, &box2) )
1589  {
1590  if ( ! gbox_overlaps_2d(&box1, &box2) )
1591  {
1592  PG_RETURN_BOOL(false);
1593  }
1594  }
1595 
1596  initGEOS(lwpgnotice, lwgeom_geos_error);
1597 
1598  g1 = POSTGIS2GEOS(geom1);
1599  if (!g1)
1600  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1601 
1602  g2 = POSTGIS2GEOS(geom2);
1603 
1604  if (!g2)
1605  {
1606  GEOSGeom_destroy(g1);
1607  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
1608  }
1609 
1610  result = GEOSOverlaps(g1,g2);
1611 
1612  GEOSGeom_destroy(g1);
1613  GEOSGeom_destroy(g2);
1614  if (result == 2) HANDLE_GEOS_ERROR("GEOSOverlaps");
1615 
1616  PG_FREE_IF_COPY(geom1, 0);
1617  PG_FREE_IF_COPY(geom2, 1);
1618 
1619  PG_RETURN_BOOL(result);
1620 }
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:330
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:100
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
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:640
void lwgeom_geos_error(const char *fmt,...)
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
#define HANDLE_GEOS_ERROR(label)
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)

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

Referenced by rt_raster_overlaps().

Here is the call graph for this function:
Here is the caller graph for this function: