516{
518 ListCell *l;
521 size_t ngeoms = 0;
522 int empty_type = 0;
523 bool first = true;
526
527 if (PG_ARGISNULL(0))
528 PG_RETURN_NULL();
529
531 geoms = palloc(list_length(state->
geoms) *
sizeof(
LWGEOM*));
532
533
534 foreach (l, state->
geoms)
535 {
537 if (geom)
538 {
540 {
541 geoms[ngeoms++] = geom;
542 if (first)
543 {
546 first = false;
547 }
548 }
549 else
550 {
552 empty_type =
type > empty_type ?
type : empty_type;
554 }
555 }
556 }
557
558
559
560
561
562 if (ngeoms > 0)
563 {
564 GEOSGeometry *g = NULL;
565 GEOSGeometry *g_union = NULL;
567
570 if (!g)
572
573 g_union = GEOSUnaryUnion(g);
574 GEOSGeom_destroy(g);
575 if (!g_union)
577
578 GEOSSetSRID(g_union, srid);
580 GEOSGeom_destroy(g_union);
581 }
582
583 else
584 {
585
586 if (empty_type > 0)
587 PG_RETURN_POINTER(
589
590
591 else
592 PG_RETURN_NULL();
593 }
594
595 if (!gser_out)
596 {
597
598 PG_RETURN_NULL();
599 }
600
601 PG_RETURN_POINTER(gser_out);
602}
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
#define SRID_UNKNOWN
Unknown SRID value.
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)