347 ArrayIterator iterator;
352 int nelems = 0, geoms_size = 0, curgeom = 0,
count = 0;
356 GEOSGeometry *g = NULL;
357 GEOSGeometry *g_union = NULL;
358 GEOSGeometry **geoms = NULL;
365 if ( PG_ARGISNULL(0) )
368 array = PG_GETARG_ARRAYTYPE_P(0);
369 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
372 if ( nelems == 0 ) PG_RETURN_NULL();
375 #if POSTGIS_PGSQL_VERSION >= 95
376 iterator = array_create_iterator(array, 0, NULL);
378 iterator = array_create_iterator(array, 0);
380 while( array_iterate(iterator, &
value, &isnull) )
383 if (isnull)
continue;
386 array_free_iterator(iterator);
394 if (
count == 1 && nelems == 1 )
396 #pragma GCC diagnostic push
397 #pragma GCC diagnostic ignored "-Wsign-compare"
398 PG_RETURN_POINTER((
GSERIALIZED *)(ARR_DATA_PTR(array)));
399 #pragma GCC diagnostic pop
409 geoms = palloc(
sizeof(GEOSGeometry*) * geoms_size);
415 #if POSTGIS_PGSQL_VERSION >= 95
416 iterator = array_create_iterator(array, 0, NULL);
418 iterator = array_create_iterator(array, 0);
420 while( array_iterate(iterator, &
value, &isnull) )
425 if (isnull)
continue;
445 if (gser_type > empty_type)
447 empty_type = gser_type;
448 POSTGIS_DEBUGF(4,
"empty_type = %d gser_type = %d", empty_type, gser_type);
459 "One of the geometries in the set "
460 "could not be converted to GEOS");
464 if ( curgeom == geoms_size )
467 geoms = repalloc( geoms,
sizeof(GEOSGeometry*) * geoms_size );
475 array_free_iterator(iterator);
483 g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
484 if (!g)
HANDLE_GEOS_ERROR(
"Could not create GEOS COLLECTION from geometry array");
486 g_union = GEOSUnaryUnion(g);
490 GEOSSetSRID(g_union, srid);
492 GEOSGeom_destroy(g_union);
498 if ( empty_type > 0 )
515 PG_RETURN_POINTER(gser_out);
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
void lwgeom_geos_error(const char *fmt,...)
void error_if_srid_mismatch(int srid1, int srid2)
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM * lwgeom_construct_empty(uint8_t type, int 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)