PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ containsproperly()

Datum containsproperly ( PG_FUNCTION_ARGS  )

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

References PrepGeomCache::argnum, covers(), error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, gbox_contains_2d(), 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().

1869 {
1870  GSERIALIZED * geom1;
1871  GSERIALIZED * geom2;
1872  bool result;
1873  GBOX box1, box2;
1874  PrepGeomCache * prep_cache;
1875 
1876  geom1 = PG_GETARG_GSERIALIZED_P(0);
1877  geom2 = PG_GETARG_GSERIALIZED_P(1);
1878 
1879  errorIfGeometryCollection(geom1,geom2);
1881 
1882  /* A.ContainsProperly(Empty) == FALSE */
1883  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
1884  PG_RETURN_BOOL(false);
1885 
1886  /*
1887  * short-circuit: if geom2 bounding box is not completely inside
1888  * geom1 bounding box we can prematurely return FALSE.
1889  */
1890  if ( gserialized_get_gbox_p(geom1, &box1) &&
1891  gserialized_get_gbox_p(geom2, &box2) )
1892  {
1893  if ( ! gbox_contains_2d(&box1, &box2) )
1894  PG_RETURN_BOOL(FALSE);
1895  }
1896 
1897  initGEOS(lwpgnotice, lwgeom_geos_error);
1898 
1899  prep_cache = GetPrepGeomCache( fcinfo, geom1, 0 );
1900 
1901  if ( prep_cache && prep_cache->prepared_geom && prep_cache->argnum == 1 )
1902  {
1903  GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1904  if ( 0 == g ) /* exception thrown at construction */
1905  {
1906  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1907  PG_RETURN_NULL();
1908  }
1909  result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
1910  GEOSGeom_destroy(g);
1911  }
1912  else
1913  {
1914  GEOSGeometry *g2;
1915  GEOSGeometry *g1;
1916 
1917  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
1918  if ( 0 == g1 ) /* exception thrown at construction */
1919  {
1920  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1921  PG_RETURN_NULL();
1922  }
1923  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
1924  if ( 0 == g2 ) /* exception thrown at construction */
1925  {
1926  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
1927  GEOSGeom_destroy(g1);
1928  PG_RETURN_NULL();
1929  }
1930  result = GEOSRelatePattern( g1, g2, "T**FF*FF*" );
1931  GEOSGeom_destroy(g1);
1932  GEOSGeom_destroy(g2);
1933  }
1934 
1935  if (result == 2)
1936  {
1937  HANDLE_GEOS_ERROR("GEOSContains");
1938  PG_RETURN_NULL(); /* never get here */
1939  }
1940 
1941  PG_FREE_IF_COPY(geom1, 0);
1942  PG_FREE_IF_COPY(geom2, 1);
1943 
1944  PG_RETURN_BOOL(result);
1945 }
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:398
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:351
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
void lwgeom_geos_error(const char *fmt,...)
#define FALSE
Definition: dbfopen.c:168
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:83
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: