375 ArrayIterator iterator;
380 int nelems = 0, geoms_size = 0, curgeom = 0,
count = 0;
384 GEOSGeometry *g = NULL;
385 GEOSGeometry *g_union = NULL;
386 GEOSGeometry **geoms = NULL;
393 if ( PG_ARGISNULL(0) )
396 array = PG_GETARG_ARRAYTYPE_P(0);
397 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
400 if ( nelems == 0 ) PG_RETURN_NULL();
403 #if POSTGIS_PGSQL_VERSION >= 95 404 iterator = array_create_iterator(array, 0, NULL);
406 iterator = array_create_iterator(array, 0);
408 while( array_iterate(iterator, &value, &isnull) )
416 array_free_iterator(iterator);
424 if (
count == 1 && nelems == 1 )
425 PG_RETURN_POINTER((
GSERIALIZED *)(ARR_DATA_PTR(array)));
434 geoms = palloc(
sizeof(GEOSGeometry*) * geoms_size);
440 #if POSTGIS_PGSQL_VERSION >= 95 441 iterator = array_create_iterator(array, 0, NULL);
443 iterator = array_create_iterator(array, 0);
445 while( array_iterate(iterator, &value, &isnull) )
472 if (gser_type > empty_type)
474 empty_type = gser_type;
475 POSTGIS_DEBUGF(4,
"empty_type = %d gser_type = %d", empty_type, gser_type);
486 "could not be converted to GEOS");
491 if ( curgeom == geoms_size )
494 geoms = repalloc( geoms,
sizeof(GEOSGeometry*) * geoms_size );
502 array_free_iterator(iterator);
510 g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
517 g_union = GEOSUnaryUnion(g);
525 GEOSSetSRID(g_union, srid);
527 GEOSGeom_destroy(g_union);
533 if ( empty_type > 0 )
550 PG_RETURN_POINTER(gser_out);
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
void error_if_srid_mismatch(int srid1, int srid2)
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.
void lwgeom_geos_error(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
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)...