479 ArrayIterator iterator;
484 int nelems = 0, geoms_size = 0, curgeom = 0,
count = 0;
488 GEOSGeometry *g = NULL;
489 GEOSGeometry *g_union = NULL;
490 GEOSGeometry **geoms = NULL;
497 if ( PG_ARGISNULL(0) )
500 array = PG_GETARG_ARRAYTYPE_P(0);
501 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
504 if ( nelems == 0 ) PG_RETURN_NULL();
507 iterator = array_create_iterator(array, 0, NULL);
508 while (array_iterate(iterator, &
value, &isnull))
511 if (isnull)
continue;
514 array_free_iterator(iterator);
525 if (
count == 1 && nelems == 1 )
527 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
528 #pragma GCC diagnostic push
529 #pragma GCC diagnostic ignored "-Wsign-compare"
532 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
533 #pragma GCC diagnostic pop
535 g_union = GEOSUnaryUnion(g);
538 GEOSSetSRID(g_union, srid);
540 GEOSGeom_destroy(g_union);
541 PG_RETURN_POINTER(gser_out);
548 geoms = palloc(
sizeof(GEOSGeometry*) * geoms_size);
554 iterator = array_create_iterator(array, 0, NULL);
555 while (array_iterate(iterator, &
value, &isnull))
560 if (isnull)
continue;
578 if (gser_type > empty_type)
580 empty_type = gser_type;
581 POSTGIS_DEBUGF(4,
"empty_type = %d gser_type = %d", empty_type, gser_type);
592 "One of the geometries in the set "
593 "could not be converted to GEOS");
597 if ( curgeom == geoms_size )
600 geoms = repalloc( geoms,
sizeof(GEOSGeometry*) * geoms_size );
608 array_free_iterator(iterator);
616 g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
617 if (!g)
HANDLE_GEOS_ERROR(
"Could not create GEOS COLLECTION from geometry array");
619 g_union = GEOSUnaryUnion(g);
623 GEOSSetSRID(g_union, srid);
625 GEOSGeom_destroy(g_union);
631 if ( empty_type > 0 )
648 PG_RETURN_POINTER(gser_out);
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
void lwgeom_geos_error(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)