PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geography_covers ( PG_FUNCTION_ARGS  )

Definition at line 620 of file geography_measurement.c.

References COLLECTIONTYPE, gserialized_get_type(), LW_FALSE, lwgeom_covers_lwgeom_sphere(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), MULTIPOINTTYPE, MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, and result.

621 {
622  LWGEOM *lwgeom1 = NULL;
623  LWGEOM *lwgeom2 = NULL;
624  GSERIALIZED *g1 = NULL;
625  GSERIALIZED *g2 = NULL;
626  int type1, type2;
627  int result = LW_FALSE;
628 
629  /* Get our geometry objects loaded into memory. */
630  g1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
631  g2 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
632 
633  type1 = gserialized_get_type(g1);
634  type2 = gserialized_get_type(g2);
635 
636  /* Right now we only handle points and polygons */
637  if ( ! ( (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE || type1 == COLLECTIONTYPE) &&
638  (type2 == POINTTYPE || type2 == MULTIPOINTTYPE || type2 == COLLECTIONTYPE) ) )
639  {
640  elog(ERROR, "geography_covers: only POLYGON and POINT types are currently supported");
641  PG_RETURN_NULL();
642  }
643 
644  /* Construct our working geometries */
645  lwgeom1 = lwgeom_from_gserialized(g1);
646  lwgeom2 = lwgeom_from_gserialized(g2);
647 
648  /* EMPTY never intersects with another geometry */
649  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
650  {
651  lwgeom_free(lwgeom1);
652  lwgeom_free(lwgeom2);
653  PG_FREE_IF_COPY(g1, 0);
654  PG_FREE_IF_COPY(g2, 1);
655  PG_RETURN_BOOL(false);
656  }
657 
658  /* Calculate answer */
659  result = lwgeom_covers_lwgeom_sphere(lwgeom1, lwgeom2);
660 
661  /* Clean up */
662  lwgeom_free(lwgeom1);
663  lwgeom_free(lwgeom2);
664  PG_FREE_IF_COPY(g1, 0);
665  PG_FREE_IF_COPY(g2, 1);
666 
667  PG_RETURN_BOOL(result);
668 }
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:56
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:2300
#define POLYGONTYPE
Definition: liblwgeom.h:62
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
char ** result
Definition: liblwgeom.h:218
#define LW_FALSE
Definition: liblwgeom.h:52
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
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:1229
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function: