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

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

References PrepGeomCache::argnum, error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, GetPrepGeomCache(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), PrepGeomCache::prepared_geom, result, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

2138 {
2139  GSERIALIZED * geom1;
2140  GSERIALIZED * geom2;
2141  bool result;
2142  GBOX box1, box2;
2143  PrepGeomCache * prep_cache;
2144 
2145  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2146  geom2 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2147 
2148  errorIfGeometryCollection(geom1,geom2);
2150 
2151  /* A.ContainsProperly(Empty) == FALSE */
2152  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2153  PG_RETURN_BOOL(false);
2154 
2155  /*
2156  * short-circuit: if geom2 bounding box is not completely inside
2157  * geom1 bounding box we can prematurely return FALSE.
2158  * Do the test IFF BOUNDING BOX AVAILABLE.
2159  */
2160  if ( gserialized_get_gbox_p(geom1, &box1) &&
2161  gserialized_get_gbox_p(geom2, &box2) )
2162  {
2163  if (( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
2164  ( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
2165  PG_RETURN_BOOL(FALSE);
2166  }
2167 
2168  initGEOS(lwnotice, 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  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
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  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2192  PG_RETURN_NULL();
2193  }
2194  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2195  if ( 0 == g2 ) /* exception thrown at construction */
2196  {
2197  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
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  lwerror("GEOSContains: %s", lwgeom_geos_errmsg);
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:373
const GEOSPreparedGeometry * prepared_geom
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
double xmax
Definition: liblwgeom.h:249
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
void lwgeom_geos_error(const char *fmt,...)
double ymax
Definition: liblwgeom.h:251
#define FALSE
Definition: dbfopen.c:169
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 ...
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:70
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: