How can I check if a geometry is contained in a geometry collection ? Specifically , I am using ST_ClusterWithin in PostGIS to get a cluster which returns each cluster as a geometry collection. Now I want to extract the cluster_id for each geometry. For this I need to check if the geometry is within the geometry collection. How can I do it ? It is related to this question I asked on stackexchange some days ago.
Asked
Active
Viewed 1,365 times
5
Nicolas Boisteault
- 1,039
- 10
- 30
Malice
- 257
- 1
- 10
-
1For the application you describe, it should be sufficient to figure out which geometry collection each input intersects. – dbaston May 31 '16 at 12:52
1 Answers
3
you can use a combination of ST_CollectionExtract and ST_Dump()
and compare results to your geometry. You will need to specify the geometry type you want to extract:
1 == POINT, 2 == LINESTRING, 3 == POLYGON
WITH c AS (
SELECT (ST_Dump(ST_CollectionExtract(geom),2)).geom AS geom
FROM my_geo_collection)
SELECT c.geom, t.geom FROM
c, my_geometry AS t
WHERE c.geom = t.geom
This might not work if your reference geometry is a multigeometry, since ST_Dump expands multi geometries into simple geometry types
Thomas
- 1,197
- 5
- 11
-
Are you sure it works? ST_Dump returns a set. In my case I have
ERROR: operator does not exist: geometry = geometry_dumperror. – Nicolas Boisteault Jun 02 '17 at 08:52 -