PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum containsproperly ( PG_FUNCTION_ARGS  )

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

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

1873 {
1874  GSERIALIZED * geom1;
1875  GSERIALIZED * geom2;
1876  bool result;
1877  GBOX box1, box2;
1878  PrepGeomCache * prep_cache;
1879 
1880  geom1 = PG_GETARG_GSERIALIZED_P(0);
1881  geom2 = PG_GETARG_GSERIALIZED_P(1);
1882 
1883  errorIfGeometryCollection(geom1,geom2);
1885 
1886  /* A.ContainsProperly(Empty) == FALSE */
1887  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1888  PG_RETURN_BOOL(false);
1889 
1890  /*
1891  * short-circuit: if geom2 bounding box is not completely inside
1892  * geom1 bounding box we can prematurely return FALSE.
1893  */
1894  if ( gserialized_get_gbox_p(geom1, &box1) &&
1895  gserialized_get_gbox_p(geom2, &box2) )
1896  {
1897  if ( ! gbox_contains_2d(&box1, &box2) )
1898  PG_RETURN_BOOL(false);
1899  }
1900 
1901  initGEOS(lwpgnotice, lwgeom_geos_error);
1902 
1903  prep_cache = GetPrepGeomCache( fcinfo, geom1, 0 );
1904 
1905  if ( prep_cache && prep_cache->prepared_geom && prep_cache->argnum == 1 )
1906  {
1907  GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1908  if (!g)
1910  "First argument geometry could not be converted to "
1911  "GEOS");
1912  result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
1913  GEOSGeom_destroy(g);
1914  }
1915  else
1916  {
1917  GEOSGeometry *g2;
1918  GEOSGeometry *g1;
1919 
1920  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
1921  if (!g1)
1923  "First argument geometry could not be converted to "
1924  "GEOS");
1925  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1926  if (!g2)
1927  {
1928  GEOSGeom_destroy(g1);
1930  "Second argument geometry could not be converted "
1931  "to GEOS");
1932  }
1933  result = GEOSRelatePattern( g1, g2, "T**FF*FF*" );
1934  GEOSGeom_destroy(g1);
1935  GEOSGeom_destroy(g2);
1936  }
1937 
1938  if (result == 2) HANDLE_GEOS_ERROR("GEOSContains");
1939 
1940  PG_FREE_IF_COPY(geom1, 0);
1941  PG_FREE_IF_COPY(geom2, 1);
1942 
1943  PG_RETURN_BOOL(result);
1944 }
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:338
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: