PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwgeom_covers_lwgeom_sphere()

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 2303 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().

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