I'm discovering PostGIS for myself and right now I'm stuck at the point with clusters. Found some tips about how to make clusters on point layer in PostGIS by using ST_ClusterWithin function. Right now I can display a clean cluster centroid data with no any other parameters.
This is my script:
SELECT ST_NumGeometries(cwn) as num_geoms, ST_Centroid(cwn) AS centroid FROM ( SELECT unnest(ST_ClusterWithin("GEOM", 0.1)) cwn FROM geodata ) f My another goal is to display some stats like quantity of specific values (0 and 1) in result table.
This is scematic picture of what I need. When cluster and its centroid are created, I'd like to see how many zeros or ones were taken from original points.
So the result should be like this
num_geoms | centroid | zeros | ones | ----------+-----------------+-------+------- 4 | geometry_object | 1 | 3 | 4 | geometry_object | 3 | 1 | 4 | geometry_object | 2 | 2 | I'm pretty sure that this can be made, but still haven't got an idea of how to make a correct query.


ST_ClusterDBSCAN- see e.g. my answer here.