PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ containsproperly()

Datum containsproperly ( PG_FUNCTION_ARGS  )

Definition at line 1761 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().

1762 {
1763  GSERIALIZED * geom1;
1764  GSERIALIZED * geom2;
1765  char result;
1766  GBOX box1, box2;
1767  PrepGeomCache * prep_cache;
1768 
1769  geom1 = PG_GETARG_GSERIALIZED_P(0);
1770  geom2 = PG_GETARG_GSERIALIZED_P(1);
1771 
1772  errorIfGeometryCollection(geom1,geom2);
1774 
1775  /* A.ContainsProperly(Empty) == FALSE */
1776  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1777  PG_RETURN_BOOL(false);
1778 
1779  /*
1780  * short-circuit: if geom2 bounding box is not completely inside
1781  * geom1 bounding box we can return FALSE.
1782  */
1783  if ( gserialized_get_gbox_p(geom1, &box1) &&
1784  gserialized_get_gbox_p(geom2, &box2) )
1785  {
1786  if ( ! gbox_contains_2d(&box1, &box2) )
1787  PG_RETURN_BOOL(false);
1788  }
1789 
1790  initGEOS(lwpgnotice, lwgeom_geos_error);
1791 
1792  prep_cache = GetPrepGeomCache( fcinfo, geom1, 0 );
1793 
1794  if ( prep_cache && prep_cache->prepared_geom && prep_cache->gcache.argnum == 1 )
1795  {
1796  GEOSGeometry *g = POSTGIS2GEOS(geom2);
1797  if (!g) HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1798  result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
1799  GEOSGeom_destroy(g);
1800  }
1801  else
1802  {
1803  GEOSGeometry *g2;
1804  GEOSGeometry *g1;
1805 
1806  g1 = POSTGIS2GEOS(geom1);
1807  if (!g1) HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1808  g2 = POSTGIS2GEOS(geom2);
1809  if (!g2)
1810  {
1811  GEOSGeom_destroy(g1);
1812  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
1813  }
1814  result = GEOSRelatePattern( g1, g2, "T**FF*FF*" );
1815  GEOSGeom_destroy(g1);
1816  GEOSGeom_destroy(g2);
1817  }
1818 
1819  if (result == 2) HANDLE_GEOS_ERROR("GEOSContains");
1820 
1821  PG_FREE_IF_COPY(geom1, 0);
1822  PG_FREE_IF_COPY(geom2, 1);
1823 
1824  PG_RETURN_BOOL(result);
1825 }
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
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:338
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
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:100
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: