PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ geography_covers()

Datum geography_covers ( PG_FUNCTION_ARGS  )

Definition at line 729 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().

730 {
731  LWGEOM *lwgeom1 = NULL;
732  LWGEOM *lwgeom2 = NULL;
733  GSERIALIZED *g1 = NULL;
734  GSERIALIZED *g2 = NULL;
735  int type1, type2;
736  int result = LW_FALSE;
737 
738  /* Get our geometry objects loaded into memory. */
739  g1 = PG_GETARG_GSERIALIZED_P(0);
740  g2 = PG_GETARG_GSERIALIZED_P(1);
741 
742  type1 = gserialized_get_type(g1);
743  type2 = gserialized_get_type(g2);
744 
745  /* Right now we only handle points and polygons */
746  if ( ! ( (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE || type1 == COLLECTIONTYPE) &&
747  (type2 == POINTTYPE || type2 == MULTIPOINTTYPE || type2 == COLLECTIONTYPE) ) )
748  {
749  elog(ERROR, "geography_covers: only POLYGON and POINT types are currently supported");
750  PG_RETURN_NULL();
751  }
752 
753  /* Construct our working geometries */
754  lwgeom1 = lwgeom_from_gserialized(g1);
755  lwgeom2 = lwgeom_from_gserialized(g2);
756 
757  error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
758 
759  /* EMPTY never intersects with another geometry */
760  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
761  {
762  lwgeom_free(lwgeom1);
763  lwgeom_free(lwgeom2);
764  PG_FREE_IF_COPY(g1, 0);
765  PG_FREE_IF_COPY(g2, 1);
766  PG_RETURN_BOOL(false);
767  }
768 
769  /* Calculate answer */
770  result = lwgeom_covers_lwgeom_sphere(lwgeom1, lwgeom2);
771 
772  /* Clean up */
773  lwgeom_free(lwgeom1);
774  lwgeom_free(lwgeom2);
775  PG_FREE_IF_COPY(g1, 0);
776  PG_FREE_IF_COPY(g2, 1);
777 
778  PG_RETURN_BOOL(result);
779 }
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:69
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:2314
#define POLYGONTYPE
Definition: liblwgeom.h:86
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
int32_t srid
Definition: liblwgeom.h:398
#define LW_FALSE
Definition: liblwgeom.h:76
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
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:1310
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
Here is the call graph for this function:
Here is the caller graph for this function: