348 ArrayIterator iterator;
353 int nelems = 0, geoms_size = 0, curgeom = 0,
count = 0;
357 GEOSGeometry *g = NULL;
358 GEOSGeometry *g_union = NULL;
359 GEOSGeometry **geoms = NULL;
366 if ( PG_ARGISNULL(0) )
369 array = PG_GETARG_ARRAYTYPE_P(0);
370 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
373 if ( nelems == 0 ) PG_RETURN_NULL();
376 iterator = array_create_iterator(array, 0, NULL);
377 while (array_iterate(iterator, &
value, &isnull))
380 if (isnull)
continue;
383 array_free_iterator(iterator);
391 if (
count == 1 && nelems == 1 )
393 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
394 #pragma GCC diagnostic push
395 #pragma GCC diagnostic ignored "-Wsign-compare"
397 PG_RETURN_POINTER((
GSERIALIZED *)(ARR_DATA_PTR(array)));
398 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
399 #pragma GCC diagnostic pop
410 geoms = palloc(
sizeof(GEOSGeometry*) * geoms_size);
416 iterator = array_create_iterator(array, 0, NULL);
417 while (array_iterate(iterator, &
value, &isnull))
422 if (isnull)
continue;
440 if (gser_type > empty_type)
442 empty_type = gser_type;
443 POSTGIS_DEBUGF(4,
"empty_type = %d gser_type = %d", empty_type, gser_type);
454 "One of the geometries in the set "
455 "could not be converted to GEOS");
459 if ( curgeom == geoms_size )
462 geoms = repalloc( geoms,
sizeof(GEOSGeometry*) * geoms_size );
470 array_free_iterator(iterator);
478 g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
479 if (!g)
HANDLE_GEOS_ERROR(
"Could not create GEOS COLLECTION from geometry array");
481 g_union = GEOSUnaryUnion(g);
485 GEOSSetSRID(g_union, srid);
487 GEOSGeom_destroy(g_union);
493 if ( empty_type > 0 )
510 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)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)