Skip to content

Commit

Permalink
ST_Union(geom[]) should unary union single entry arrays
Browse files Browse the repository at this point in the history
References #5677
  • Loading branch information
pramsey committed Feb 26, 2024
1 parent c90e282 commit bd10d04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -3,6 +3,7 @@ PostGIS 3.2.8

* Bug Fixes *

- #5677, ST_Union(geom[]) should unary union single entry arrays (Paul Ramsey)


PostGIS 3.2.7
Expand Down
15 changes: 11 additions & 4 deletions postgis/lwgeom_geos.c
Expand Up @@ -518,22 +518,29 @@ Datum pgis_union_geometry_array(PG_FUNCTION_ARGS)
if ( count == 0 )
PG_RETURN_NULL();

/* Ok, we really need GEOS now ;) */
initGEOS(lwpgnotice, lwgeom_geos_error);

/* One geom, good geom? Return it */
if ( count == 1 && nelems == 1 )
{
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif
PG_RETURN_POINTER((GSERIALIZED *)(ARR_DATA_PTR(array)));
g = POSTGIS2GEOS((GSERIALIZED *)(ARR_DATA_PTR(array)));
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic pop
#endif
g_union = GEOSUnaryUnion(g);
GEOSGeom_destroy(g);
if (!g_union) HANDLE_GEOS_ERROR("GEOSUnaryUnion");
GEOSSetSRID(g_union, srid);
gser_out = GEOS2POSTGIS(g_union, is3d);
GEOSGeom_destroy(g_union);
PG_RETURN_POINTER(gser_out);
}

/* Ok, we really need GEOS now ;) */
initGEOS(lwpgnotice, lwgeom_geos_error);

/*
** Collect the non-empty inputs and stuff them into a GEOS collection
*/
Expand Down

0 comments on commit bd10d04

Please sign in to comment.