PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_CoverageUnion()

Datum ST_CoverageUnion ( PG_FUNCTION_ARGS  )

Definition at line 796 of file lwgeom_window.c.

797 {
798 #if POSTGIS_GEOS_VERSION < 30800
799  lwpgerror("The GEOS version this PostGIS binary "
800  "was compiled against (%d) doesn't support "
801  "'GEOSCoverageUnion' function (3.8.0+ required)",
803  PG_RETURN_NULL();
804 
805 #else /* POSTGIS_GEOS_VERSION >= 30800 */
806 
807  GSERIALIZED *result = NULL;
808 
809  Datum value;
810  bool isnull;
811 
812  GEOSGeometry **geoms = NULL;
813  GEOSGeometry *geos = NULL;
814  GEOSGeometry *geos_result = NULL;
815  uint32 ngeoms = 0;
816 
817  ArrayType *array = PG_GETARG_ARRAYTYPE_P(0);
818  uint32 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
819  ArrayIterator iterator = array_create_iterator(array, 0, NULL);
820 
821  /* Return null on 0-elements input array */
822  if (nelems == 0)
823  PG_RETURN_NULL();
824 
825  /* Convert all geometries into GEOSGeometry array */
826  geoms = palloc(sizeof(GEOSGeometry *) * nelems);
827 
828  initGEOS(lwpgnotice, lwgeom_geos_error);
829 
830  while (array_iterate(iterator, &value, &isnull))
831  {
832  GSERIALIZED *gser;
833  /* Omit nulls */
834  if (isnull) continue;
835 
836  /* Omit empty */
837  gser = (GSERIALIZED *)DatumGetPointer(value);
838  if (gserialized_is_empty(gser)) continue;
839 
840  /* Omit unconvertable */
841  geos = POSTGIS2GEOS(gser);
842  if (!geos) continue;
843 
844  geoms[ngeoms++] = geos;
845  }
846  array_free_iterator(iterator);
847 
848  if (ngeoms == 0)
849  PG_RETURN_NULL();
850 
851  geos = GEOSGeom_createCollection(
852  GEOS_GEOMETRYCOLLECTION,
853  geoms, ngeoms);
854 
855  if (!geos)
856  {
857  coverage_destroy_geoms(geoms, ngeoms);
858  HANDLE_GEOS_ERROR("Geometry could not be converted");
859  }
860 
861  geos_result = GEOSCoverageUnion(geos);
862  GEOSGeom_destroy(geos);
863  if (!geos_result)
864  HANDLE_GEOS_ERROR("Error computing coverage union");
865 
866  result = GEOS2POSTGIS(geos_result, LW_FALSE);
867  GEOSGeom_destroy(geos_result);
868 
869  PG_RETURN_POINTER(result);
870 #endif
871 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:94
static void coverage_destroy_geoms(GEOSGeometry **geoms, uint32 ngeoms)
int value
Definition: genraster.py:62
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:11

References coverage_destroy_geoms(), GEOS2POSTGIS(), gserialized_is_empty(), HANDLE_GEOS_ERROR, LW_FALSE, lwgeom_geos_error(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, result, and genraster::value.

Referenced by pgis_geometry_coverageunion_finalfn().

Here is the call graph for this function:
Here is the caller graph for this function: