PostGIS  2.3.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 2314 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().

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