From e8436d3843c975b167f9c9f253e412b57a429ea9 Mon Sep 17 00:00:00 2001
From: Daniel Baston <dbaston@gmail.com>
Date: Fri, 23 Mar 2018 19:47:53 +0000
Subject: [PATCH] Avoid dropping SRID in ST_ClusterWithin

Resolves #4055



git-svn-id: http://svn.osgeo.org/postgis/trunk@16489 b70326c6-7e19-0410-871a-916f4a2858ee
---
 liblwgeom/lwgeom_geos_cluster.c | 4 +++-
 regress/tickets.sql             | 3 +++
 regress/tickets_expected        | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/liblwgeom/lwgeom_geos_cluster.c b/liblwgeom/lwgeom_geos_cluster.c
index 00f7693cf..e10e8eb10 100644
--- a/liblwgeom/lwgeom_geos_cluster.c
+++ b/liblwgeom/lwgeom_geos_cluster.c
@@ -570,7 +570,9 @@ combine_geometries(UNIONFIND* uf, void** geoms, uint32_t num_geoms, void*** clus
 			}
 			else
 			{
-				(*clusterGeoms)[k++] = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, (GEOSGeometry**) geoms_in_cluster, j);
+				GEOSGeometry* combined = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, (GEOSGeometry**) geoms_in_cluster, j);
+				GEOSSetSRID(combined, GEOSGetSRID(((GEOSGeometry**) geoms_in_cluster)[0]));
+				(*clusterGeoms)[k++] = combined;
 			}
 			j = 0;
 		}
diff --git a/regress/tickets.sql b/regress/tickets.sql
index 974620f14..adcdb5697 100644
--- a/regress/tickets.sql
+++ b/regress/tickets.sql
@@ -1081,5 +1081,8 @@ SELECT '#4037.2', ST_AsText(ST_Difference('POLYGON((0 0, 10 10, 0 10, 10 0, 0 0)
 SELECT '#4037.3', ST_AsText(ST_SymDifference('POLYGON((0 0, 10 10, 0 10, 10 0, 0 0))', ST_MakeEnvelope(2,2,8,8)));
 SELECT '#4037.4', ST_AsText(ST_Union('POLYGON((0 0, 10 10, 0 10, 10 0, 0 0))', ST_MakeEnvelope(2,2,8,8)));
 
+-- #4055
+SELECT '#4055', ST_SRID(unnest(ST_ClusterWithin(ARRAY['SRID=4326;POINT (3 7)'::geometry, 'SRID=4326;LINESTRING (3 0, 3 9)'], 0)));
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
diff --git a/regress/tickets_expected b/regress/tickets_expected
index 2e4084352..9e795ec87 100644
--- a/regress/tickets_expected
+++ b/regress/tickets_expected
@@ -346,3 +346,4 @@ NOTICE:  Self-intersection
 NOTICE:  Your geometry dataset is not valid per OGC Specification. Please fix it with manual review of entries that are not ST_IsValid(geom). Retrying GEOS operation with ST_MakeValid of your input.
 NOTICE:  Self-intersection
 #4037.4|POLYGON((0 0,2 2,2 8,0 10,10 10,8 8,8 2,10 0,0 0))
+#4055|4326
-- 
2.40.0