PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ containsproperly()

Datum containsproperly ( PG_FUNCTION_ARGS  )

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

2139 {
2140  GSERIALIZED * geom1;
2141  GSERIALIZED * geom2;
2142  bool result;
2143  GBOX box1, box2;
2144  PrepGeomCache * prep_cache;
2145 
2146  geom1 = PG_GETARG_GSERIALIZED_P(0);
2147  geom2 = PG_GETARG_GSERIALIZED_P(1);
2148 
2149  errorIfGeometryCollection(geom1,geom2);
2151 
2152  /* A.ContainsProperly(Empty) == FALSE */
2153  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2154  PG_RETURN_BOOL(false);
2155 
2156  /*
2157  * short-circuit: if geom2 bounding box is not completely inside
2158  * geom1 bounding box we can prematurely return FALSE.
2159  * Do the test IFF BOUNDING BOX AVAILABLE.
2160  */
2161  if ( gserialized_get_gbox_p(geom1, &box1) &&
2162  gserialized_get_gbox_p(geom2, &box2) )
2163  {
2164  if ( ! gbox_contains_2d(&box1, &box2) )
2165  PG_RETURN_BOOL(FALSE);
2166  }
2167 
2168  initGEOS(lwpgnotice, lwgeom_geos_error);
2169 
2170  prep_cache = GetPrepGeomCache( fcinfo, geom1, 0 );
2171 
2172  if ( prep_cache && prep_cache->prepared_geom && prep_cache->argnum == 1 )
2173  {
2174  GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2175  if ( 0 == g ) /* exception thrown at construction */
2176  {
2177  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2178  PG_RETURN_NULL();
2179  }
2180  result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
2181  GEOSGeom_destroy(g);
2182  }
2183  else
2184  {
2185  GEOSGeometry *g2;
2186  GEOSGeometry *g1;
2187 
2188  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2189  if ( 0 == g1 ) /* exception thrown at construction */
2190  {
2191  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2192  PG_RETURN_NULL();
2193  }
2194  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2195  if ( 0 == g2 ) /* exception thrown at construction */
2196  {
2197  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2198  GEOSGeom_destroy(g1);
2199  PG_RETURN_NULL();
2200  }
2201  result = GEOSRelatePattern( g1, g2, "T**FF*FF*" );
2202  GEOSGeom_destroy(g1);
2203  GEOSGeom_destroy(g2);
2204  }
2205 
2206  if (result == 2)
2207  {
2208  HANDLE_GEOS_ERROR("GEOSContains");
2209  PG_RETURN_NULL(); /* never get here */
2210  }
2211 
2212  PG_FREE_IF_COPY(geom1, 0);
2213  PG_FREE_IF_COPY(geom2, 1);
2214 
2215  PG_RETURN_BOOL(result);
2216 }
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:371
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:316
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
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:69
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: