PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ST_CoverageUnion()

Datum ST_CoverageUnion ( PG_FUNCTION_ARGS  )

Definition at line 888 of file lwgeom_window.c.

889{
890 GSERIALIZED *result = NULL;
891
892 Datum value;
893 bool isnull;
894
895 GEOSGeometry **geoms = NULL;
896 GEOSGeometry *geos = NULL;
897 GEOSGeometry *geos_result = NULL;
898 uint32 ngeoms = 0;
899
900 ArrayType *array = PG_GETARG_ARRAYTYPE_P(0);
901 uint32 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
902 ArrayIterator iterator = array_create_iterator(array, 0, NULL);
903
904 /* Return null on 0-elements input array */
905 if (nelems == 0)
906 PG_RETURN_NULL();
907
908 /* Convert all geometries into GEOSGeometry array */
909 geoms = palloc(sizeof(GEOSGeometry *) * nelems);
910
911 initGEOS(lwpgnotice, lwgeom_geos_error);
912
913 while (array_iterate(iterator, &value, &isnull))
914 {
915 GSERIALIZED *gser;
916 /* Omit nulls */
917 if (isnull) continue;
918
919 /* Omit empty */
920 gser = (GSERIALIZED *)DatumGetPointer(value);
921 if (gserialized_is_empty(gser)) continue;
922
923 /* Omit unconvertible */
924 geos = POSTGIS2GEOS(gser);
925 if (!geos) continue;
926
927 geoms[ngeoms++] = geos;
928 }
929 array_free_iterator(iterator);
930
931 if (ngeoms == 0)
932 PG_RETURN_NULL();
933
934 geos = GEOSGeom_createCollection(
935 GEOS_GEOMETRYCOLLECTION,
936 geoms, ngeoms);
937
938 if (!geos)
939 {
940 coverage_destroy_geoms(geoms, ngeoms);
941 HANDLE_GEOS_ERROR("Geometry could not be converted");
942 }
943
944 geos_result = GEOSCoverageUnion(geos);
945 GEOSGeom_destroy(geos);
946 if (!geos_result)
947 HANDLE_GEOS_ERROR("Error computing coverage union");
948
949 result = GEOS2POSTGIS(geos_result, LW_FALSE);
950 GEOSGeom_destroy(geos_result);
951
952 PG_RETURN_POINTER(result);
953}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
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)

References coverage_destroy_geoms(), GEOS2POSTGIS(), gserialized_is_empty(), HANDLE_GEOS_ERROR, LW_FALSE, lwgeom_geos_error(), POSTGIS2GEOS(), and result.

Referenced by pgis_geometry_coverageunion_finalfn().

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