PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ geography_covers()

Datum geography_covers ( PG_FUNCTION_ARGS  )

Definition at line 712 of file geography_measurement.c.

References COLLECTIONTYPE, error_if_srid_mismatch(), geography_bestsrid(), gserialized_get_type(), LW_FALSE, lwgeom_covers_lwgeom_sphere(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), MULTIPOINTTYPE, MULTIPOLYGONTYPE, PG_FUNCTION_INFO_V1(), POINTTYPE, POLYGONTYPE, and LWGEOM::srid.

Referenced by geography_point_outside().

713 {
714  LWGEOM *lwgeom1 = NULL;
715  LWGEOM *lwgeom2 = NULL;
716  GSERIALIZED *g1 = NULL;
717  GSERIALIZED *g2 = NULL;
718  int type1, type2;
719  int result = LW_FALSE;
720 
721  /* Get our geometry objects loaded into memory. */
722  g1 = PG_GETARG_GSERIALIZED_P(0);
723  g2 = PG_GETARG_GSERIALIZED_P(1);
724 
725  type1 = gserialized_get_type(g1);
726  type2 = gserialized_get_type(g2);
727 
728  /* Right now we only handle points and polygons */
729  if ( ! ( (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE || type1 == COLLECTIONTYPE) &&
730  (type2 == POINTTYPE || type2 == MULTIPOINTTYPE || type2 == COLLECTIONTYPE) ) )
731  {
732  elog(ERROR, "geography_covers: only POLYGON and POINT types are currently supported");
733  PG_RETURN_NULL();
734  }
735 
736  /* Construct our working geometries */
737  lwgeom1 = lwgeom_from_gserialized(g1);
738  lwgeom2 = lwgeom_from_gserialized(g2);
739 
740  error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
741 
742  /* EMPTY never intersects with another geometry */
743  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
744  {
745  lwgeom_free(lwgeom1);
746  lwgeom_free(lwgeom2);
747  PG_FREE_IF_COPY(g1, 0);
748  PG_FREE_IF_COPY(g2, 1);
749  PG_RETURN_BOOL(false);
750  }
751 
752  /* Calculate answer */
753  result = lwgeom_covers_lwgeom_sphere(lwgeom1, lwgeom2);
754 
755  /* Clean up */
756  lwgeom_free(lwgeom1);
757  lwgeom_free(lwgeom2);
758  PG_FREE_IF_COPY(g1, 0);
759  PG_FREE_IF_COPY(g2, 1);
760 
761  PG_RETURN_BOOL(result);
762 }
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int32_t srid
Definition: liblwgeom.h:383
#define LW_FALSE
Definition: liblwgeom.h:62
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
Here is the call graph for this function:
Here is the caller graph for this function: