Skip to main content
13 votes

Clustering points in PostGIS

I'd suggest to use the ST_ClusterDBSCAN Window function rather than the Aggregate function ST_ClusterWithin: SELECT *, ST_ClusterDBSCAN(the_geom, eps := <distance>, minpoints := 1) OVER()...
geozelot's user avatar
  • 30.4k
8 votes
Accepted

Raster clustering using QGIS

If you prefer to address this issue in "the raster logic", then there are a few filters that you could consider. The best choice will depend on the spatial distribution of your pixels of each class ...
radouxju's user avatar
  • 49.8k
7 votes
Accepted

PostGIS Recursively Finding Intersections of Polygons to Determine Clusters

You really want to use the mighty ST_ClusterDBSCAN: SELECT *, ST_ClusterDBSCAN(geom, 0, 1) OVER() AS clst_id FROM <your_table> ; where clst_id is an integer value representing the ...
geozelot's user avatar
  • 30.4k
6 votes

Understanding ST_ClusterWithin

ST_ClusterWithin is an aggregator function, meaning it will not generate a new geometry, but simply output the geometries that were input to it, albeit in a particular grouping (the clusters, in this ...
Roberto Ribeiro's user avatar
5 votes
Accepted

ST_ClusterDBSCAN in PostGIS gives me 0 for the cluster ID

20000 is most probably in degrees - which is why all of your geometries are in cluster 0 (if it was failing to cluster they would be in NULL). You need to convert your data to be in metres by ...
Ian Turton's user avatar
  • 82k
5 votes
Accepted

How to UPDATE a column with cluster IDs in PostGIS?

You can do this. First, create the column in your table. ALTER TABLE point ADD COLUMN cid integer; Then update your table based on your query. When you do your DBScan query. Make sure you select ...
Edmond's user avatar
  • 66
5 votes

Seeking Fréchet distance implementation (Python) to cluster trajectories by similarity

Interesting, haven't seen the Fréchet distance before (it seems to be the equivalent of Hausdorff distance, but for lines rather than polygons) It looks as if there may be an implementation in the ...
Steven Kay's user avatar
  • 20.5k
4 votes

Creating Groups of points based on proximity in QGIS?

You can use ClusterPoint plugin. After installing the plugin, a tool named doCluster is added to Processing Toolbox. Cluster Points adds a new field Cluster_IDto the attribute table as output. (In ...
Kadir Şahbaz's user avatar
4 votes
Accepted

Dissolving polygons on distance condition using PostGIS?

The buffer-intersection construct in general is better be avoided in favor of the (for some reason not always index driven, but still) more efficient ST_DWithin. However, you will still need to ...
geozelot's user avatar
  • 30.4k
4 votes

Point cluster in ArcGIS Javascript API 4.3?

Unfortunately, this is not possible through the current version it is planned though as future updates occur for this version. ArcGIS API for JavaScript 3.20 Does have this capability.
whyzar's user avatar
  • 12.1k
4 votes
Accepted

Cluster geometries that touch each other

Make an adjacency list: touching_list = st_touches(milan_primary_highways) this isn't NxN so won't grow - its a list of length N where each element is only the adjacent elements. This might help it ...
Spacedman's user avatar
  • 64.7k
4 votes
Accepted

Statistic for measuring (local) autocorrelation of ordinal data

In terms of a local autocorrelation (nonstationarity) statistics, there really is not one. Join-counts is adequate for hypothesis testing of global clustering in binary process, albeit very scale ...
Jeffrey Evans's user avatar
4 votes
Accepted

Cluster polygons into equal parts in QGIS

Since there is no need to count `values' in this knapsack problem, the algorithm can be simplified. I wrote a script that generates random data and groups objects until their value (biomass) exceeds ...
Comrade Che's user avatar
  • 7,251
3 votes

Clustering spatial lines in R by direction

Let's work through a Haussdorf clustering of lines. We'll use the sf package for spatial data and distance calculations: library(sf) starting with your final x, lets group everything by cyclone ...
Spacedman's user avatar
  • 64.7k
3 votes

How to use ST_Contains() with ST_ClusterWithin()

It's unclear to me what you are trying to do here, but if you need to do an unnest, you are better off using ST_ClusterDBScan if you have PostGIS 2.3+. I'm also not clear why you have two calls to ...
Regina Obe's user avatar
  • 10.5k
3 votes

Run spatial clustering by inputting coordinates to cluster algorithm

Just a technicality (should be a comment but I lack reputation): In any case this needs a coordinate reference system that gives you euclidean distances in your attribute space, for example UTM: ...
Ma Ba's user avatar
  • 71
3 votes

Applying ST_ClusterDBSCAN repeatedly until cluster sizes small enough

I have been able to work around the limitation by "pre-computing" the values for eps and inferring reasonable values of the other subqueries which where previously referring to the recursive CTE. ...
Pedro's user avatar
  • 163
3 votes
Accepted

Applying ST_ClusterDBSCAN repeatedly until cluster sizes small enough

No time for more improving or testing, but: for a single, more generic recursive term, and possibly better performance, try WITH RECURSIVE params AS ( -- convenience ...
geozelot's user avatar
  • 30.4k
3 votes
Accepted

Clustering geometry points, return a point's label if the point does not belong to a cluster?

You get an entry for each voter because you are grouping on the voter column as well, which results in groups that are all single rows. And you cannot include voter_name in the query unless you either ...
jufaua's user avatar
  • 308
3 votes
Accepted

Create point clusters based on grid

Given you already have your RED 6km span points which I am referring to red_points, you can do something like this to obtain your 3X3 200m grey_points. (please, adjust the sign (+/-) as you wish to ...
umbe1987's user avatar
  • 3,785
3 votes

Clustering large number of locations

Vast question, a matrix distance is really not the way to go for a lot of points. If you want to do it yourself, look into quadtree and nearest neighbourg. The classicals algorithms used for ...
robin loche's user avatar
  • 2,475
3 votes

If a Moran's I value is close to 1, then why is it necessary to report the p-value?

It is important to additionally report the p-value because Moran's I values are often not standardized and so they are not comparable to each other. If you were trying to find the Moran's I of some ...
Randcelot's user avatar
  • 191
3 votes
Accepted

ClusterDBSCAN eps unit is meter or degrees if SRID is 4326

No. You are looking at an eps distance of 100 degrees! ST_ClusterDBSCAN currently has no signature accepting a GEOGRAPHY, so your only option is to ST_Transform your input GEOMETRYs to a suitable ...
geozelot's user avatar
  • 30.4k
2 votes

Point cluster in ArcGIS Javascript API 4.3?

The GitHub page linked below contains a clustering example for v4.x (this if from the above comments) https://github.com/nickcam/FlareClusterLayer
Steven's user avatar
  • 43
2 votes

Seeking Fréchet distance implementation (Python) to cluster trajectories by similarity

GEOS (and therefore PostGIS) also has Frechet distance. I imagine that you can use its python interface - (pygeos). Note that pygeos has been merged with Shapely and released as part of Shapely 2.0. ...
tinlyx's user avatar
  • 11.1k
2 votes

How to re-assign attributes based on spatial relationship

I've done something similar to this hundreds of times. You didn't provide enough information to provide more than a stick-figure solution, but one way to do it would look like this: UPDATE mytable t ...
Vince's user avatar
  • 20.1k
2 votes

Spatial clustering points on a spatial network in QGIS / PostGIS

I use the query construct at the end of the answer to assign census data to parts of the small transect pieces and adopted it to your context. IMO the st_distance and st_shortestline will do the right ...
huckfinn's user avatar
  • 3,603
2 votes
Accepted

Combining points close to one another

My interpretation of your question is that you are not simply trying to set a zoom level on an interactive map, and your point groups near each other do not share a common attribute. If my ...
pdavis's user avatar
  • 827
2 votes

Clustering spatially connected polygons so all clusters have approximately the same size

I finally found a way, I scripted my own clustering function in R which works relatively great. The idea is to start from the neighbor list and iteratively make groups. The algorithm looks a little ...
Bastien's user avatar
  • 639
2 votes
Accepted

Get the probable right location from multiple points

ST_GeometricMedian should compensate for outliers in MultiPoint geometries, e.g. sth. like: SELECT ST_GeometricMedian(ST_Collect(geom)) AS geom FROM <your_table> GROUP BY item_id ; ...
geozelot's user avatar
  • 30.4k

Only top scored, non community-wiki answers of a minimum length are eligible