PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ containsproperly()

Datum containsproperly ( PG_FUNCTION_ARGS  )

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

References covers(), error_if_srid_mismatch(), errorIfGeometryCollection(), gbox_contains_2d(), PrepGeomCache::gcache, GetPrepGeomCache(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and PrepGeomCache::prepared_geom.

Referenced by contains().

1761 {
1762  GSERIALIZED * geom1;
1763  GSERIALIZED * geom2;
1764  char result;
1765  GBOX box1, box2;
1766  PrepGeomCache * prep_cache;
1767 
1768  geom1 = PG_GETARG_GSERIALIZED_P(0);
1769  geom2 = PG_GETARG_GSERIALIZED_P(1);
1770 
1771  errorIfGeometryCollection(geom1,geom2);
1773 
1774  /* A.ContainsProperly(Empty) == FALSE */
1775  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1776  PG_RETURN_BOOL(false);
1777 
1778  /*
1779  * short-circuit: if geom2 bounding box is not completely inside
1780  * geom1 bounding box we can return FALSE.
1781  */
1782  if ( gserialized_get_gbox_p(geom1, &box1) &&
1783  gserialized_get_gbox_p(geom2, &box2) )
1784  {
1785  if ( ! gbox_contains_2d(&box1, &box2) )
1786  PG_RETURN_BOOL(false);
1787  }
1788 
1789  initGEOS(lwpgnotice, lwgeom_geos_error);
1790 
1791  prep_cache = GetPrepGeomCache( fcinfo, geom1, 0 );
1792 
1793  if ( prep_cache && prep_cache->prepared_geom && prep_cache->gcache.argnum == 1 )
1794  {
1795  GEOSGeometry *g = POSTGIS2GEOS(geom2);
1796  if (!g) HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1797  result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
1798  GEOSGeom_destroy(g);
1799  }
1800  else
1801  {
1802  GEOSGeometry *g2;
1803  GEOSGeometry *g1;
1804 
1805  g1 = POSTGIS2GEOS(geom1);
1806  if (!g1) HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1807  g2 = POSTGIS2GEOS(geom2);
1808  if (!g2)
1809  {
1810  GEOSGeom_destroy(g1);
1811  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
1812  }
1813  result = GEOSRelatePattern( g1, g2, "T**FF*FF*" );
1814  GEOSGeom_destroy(g1);
1815  GEOSGeom_destroy(g2);
1816  }
1817 
1818  if (result == 2) HANDLE_GEOS_ERROR("GEOSContains");
1819 
1820  PG_FREE_IF_COPY(geom1, 0);
1821  PG_FREE_IF_COPY(geom2, 1);
1822 
1823  PG_RETURN_BOOL(result);
1824 }
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:639
const GEOSPreparedGeometry * prepared_geom
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:346
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:336
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
PrepGeomCache * GetPrepGeomCache(FunctionCallInfoData *fcinfo, GSERIALIZED *g1, GSERIALIZED *g2)
Given a couple potential geometries and a function call context, return a prepared structure for one ...
#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:99
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: