PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ containsproperly()

Datum containsproperly ( PG_FUNCTION_ARGS  )

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

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

References 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(), POSTGIS2GEOS(), and PrepGeomCache::prepared_geom.

Here is the call graph for this function: