PostGIS  2.1.10dev-r@@SVN_REVISION@@
int lwgeom_covers_lwgeom_sphere ( const LWGEOM lwgeom1,
const LWGEOM lwgeom2 
)

Calculate covers predicate for two lwgeoms on the sphere.

Currently only handles point-in-polygon.

Definition at line 2300 of file lwgeodetic.c.

References LWGEOM::bbox, COLLECTIONTYPE, GBOX::flags, LWCOLLECTION::geoms, getPoint2d_p(), LW_FALSE, LW_TRUE, lwerror(), lwgeom_calculate_gbox_geodetic(), lwpoly_covers_point2d(), lwtype_is_collection(), MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, and LWGEOM::type.

Referenced by geography_covers().

2301 {
2302  int type1, type2;
2303  GBOX gbox1, gbox2;
2304  gbox1.flags = gbox2.flags = 0;
2305 
2306  assert(lwgeom1);
2307  assert(lwgeom2);
2308 
2309  type1 = lwgeom1->type;
2310  type2 = lwgeom2->type;
2311 
2312  /* Currently a restricted implementation */
2313  if ( ! ( (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE || type1 == COLLECTIONTYPE) &&
2314  (type2 == POINTTYPE || type2 == MULTIPOINTTYPE || type2 == COLLECTIONTYPE) ) )
2315  {
2316  lwerror("lwgeom_covers_lwgeom_sphere: only POLYGON covers POINT tests are currently supported");
2317  return LW_FALSE;
2318  }
2319 
2320  /* Make sure we have boxes */
2321  if ( lwgeom1->bbox )
2322  gbox1 = *(lwgeom1->bbox);
2323  else
2324  lwgeom_calculate_gbox_geodetic(lwgeom1, &gbox1);
2325 
2326  /* Make sure we have boxes */
2327  if ( lwgeom2->bbox )
2328  gbox2 = *(lwgeom2->bbox);
2329  else
2330  lwgeom_calculate_gbox_geodetic(lwgeom2, &gbox2);
2331 
2332 
2333  /* Handle the polygon/point case */
2334  if ( type1 == POLYGONTYPE && type2 == POINTTYPE )
2335  {
2336  POINT2D pt_to_test;
2337  getPoint2d_p(((LWPOINT*)lwgeom2)->point, 0, &pt_to_test);
2338  return lwpoly_covers_point2d((LWPOLY*)lwgeom1, &pt_to_test);
2339  }
2340 
2341  /* If any of the first argument parts covers the second argument, it's true */
2342  if ( lwtype_is_collection( type1 ) )
2343  {
2344  int i;
2345  LWCOLLECTION *col = (LWCOLLECTION*)lwgeom1;
2346 
2347  for ( i = 0; i < col->ngeoms; i++ )
2348  {
2349  if ( lwgeom_covers_lwgeom_sphere(col->geoms[i], lwgeom2) )
2350  {
2351  return LW_TRUE;
2352  }
2353  }
2354  return LW_FALSE;
2355  }
2356 
2357  /* Only if all of the second arguments are covered by the first argument is the condition true */
2358  if ( lwtype_is_collection( type2 ) )
2359  {
2360  int i;
2361  LWCOLLECTION *col = (LWCOLLECTION*)lwgeom2;
2362 
2363  for ( i = 0; i < col->ngeoms; i++ )
2364  {
2365  if ( ! lwgeom_covers_lwgeom_sphere(lwgeom1, col->geoms[i]) )
2366  {
2367  return LW_FALSE;
2368  }
2369  }
2370  return LW_TRUE;
2371  }
2372 
2373  /* Don't get here */
2374  lwerror("lwgeom_covers_lwgeom_sphere: reached end of function without resolution");
2375  return LW_FALSE;
2376 
2377 }
GBOX * bbox
Definition: liblwgeom.h:354
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2300
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
LWGEOM ** geoms
Definition: liblwgeom.h:465
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2612
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:955
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
uint8_t flags
Definition: liblwgeom.h:247
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
int lwpoly_covers_point2d(const LWPOLY *poly, const POINT2D *pt_to_test)
Given a polygon (lon/lat decimal degrees) and point (lon/lat decimal degrees) and a guaranteed outsid...
Definition: lwgeodetic.c:2384
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: