v.cluster(1grass)

✨ v.cluster ✨

okay bestie, pull up a chair, because this is the GRASS User's Manual page for v.cluster and it is lowkey the most slay way to make clusters out of a pile of points. no cap. πŸ’–

🌸 NAME 🌸

v.cluster β€” it performs cluster identification. that's it, that's the whole job. πŸ’…

πŸŽ€ KEYWORDS πŸŽ€

vector, point cloud, cluster, clump, level1 β€” yes the keyword list ate and left no crumbs.


πŸ¦‹ SYNOPSIS πŸ¦‹

so this is how you summon it:

v.cluster
v.cluster --help
v.cluster [-2bt] input=name output=name  [layer=string]
[distance=float]   [min=integer]   [method=string]   [--overwrite]
[--help]  [--verbose]  [--quiet]  [--ui]

🌈 Flags (the little switches that change the vibe)

  • -2 β€” force 2D clustering. like, we're pretending the z axis does not exist, bye πŸ™ˆ
  • -b β€” do NOT build topology. this is advantageous when handling a large number of points, so if your point cloud is huge, this is your bestie fr fr
  • -t β€” do not create an attribute table. no table, no problem 🫢
  • --overwrite β€” allow output files to overwrite existing files. it will absolutely bulldoze what's already there, so know that going in
  • --help β€” print usage summary
  • --verbose β€” verbose module output (it talk talk talks)
  • --quiet β€” quiet module output (it shuts UPPP 🀫)
  • --ui β€” force launching GUI dialog

πŸ“ Parameters

  • input=name [required] β€” name of input vector map. or, plot twist, a data source for direct OGR access
  • output=name [required] β€” name for output vector map
  • layer=string β€” layer number or name for cluster ids. here's the thing: vector features can have category values in different layers, and this number determines which layer to use. when used with direct OGR access this is the layer name. Default: 2
  • distance=float β€” maximum distance to neighbors
  • min=integer β€” minimum number of points to create a cluster
  • method=string β€” clustering method. options: dbscan, dbscan2, density, optics, optics2. Default: dbscan

πŸ’œ DESCRIPTION πŸ’œ

v.cluster partitions a point cloud into clusters or clumps. the way that it just... divides points up. iconic.

If the minimum number of points is not specified with the min option, the minimum number of points to constitute a cluster is number of dimensions + 1, i.e. 3 for 2D points and 4 for 3D points. so it's not just making up numbers, there's a whole rule. ✨

If the maximum distance is not specified with the distance option, the maximum distance is estimated from the observed distances to the neighbors using the upper 99% confidence interval. very demure, very statistically mindful.

v.cluster supports different methods for clustering. the recommended ones are:

  • method=dbscan β€” if all clusters should have a density (maximum distance between points) not larger than distance
  • method=density β€” if clusters should be created separately for each observed density (distance to the farthest neighbor)

πŸ‘‘ Clustering methods

πŸ”₯ dbscan method

The Density-Based Spatial Clustering of Applications with Noise is a commonly used clustering algorithm. A new cluster is started for a point with at least min - 1 neighbors within the maximum distance. These neighbors are added to the cluster. The cluster is then expanded as long as at least min - 1 neighbors are within the maximum distance for each point already in the cluster. it just keeps growing. main character energy. πŸ’…

πŸ”₯ dbscan2 method

Similar to dbscan, but here it is sufficient if the resultant cluster consists of at least min points, even if no point in the cluster has at least min - 1 neighbors within distance. softer rules, same goals 🫢

πŸ”₯ density method

This method creates clusters according to their point density. The maximum distance is not used. Instead, the points are sorted ascending by the distance to their farthest neighbor (core distance), inspecting min - 1 neighbors. The densest cluster is created first, using as threshold the core distance of the seed point. The cluster is expanded as for DBSCAN, with the difference that each cluster has its own maximum distance. This method can identify clusters with different densities and can create nested clusters. nesting!! like a lil point cloud family tree 🌸

πŸ”₯ optics method

This method is Ordering Points to Identify the Clustering Structure. It is controlled by the number of neighbor points (option min - 1). The core distance of a point is the distance to the farthest neighbor. The reachability of a point q is its distance from a point p (original optics: max(core-distance(p), distance(p, q))). The aim of the optics method is to reduce the reachability of each point. Each unprocessed point is the seed for a new cluster. Its neighbors are added to a queue sorted by smallest reachability if their reachability can be reduced. The points in the queue are processed and their unprocessed neighbors are added to a queue sorted by smallest reachability if their reachability can be reduced.

The optics method does not create clusters itself, but produces an ordered list of the points together with their reachability. The output list is ordered according to the order of processing: the first point processed is the first in the list, the last point processed is the last in the list. Clusters can be extracted from this list by identifying valleys in the points' reachability, e.g. by using a threshold value. If a maximum distance is specified, this is used to identify clusters, otherwise each separated network will constitute a cluster.

fr fr heads up: the OPTICS algorithm uses each yet unprocessed point to start a new cluster. The order of the input points is arbitrary and can thus influence the resultant clusters. so like, shuffle the input and get a different answer. that's not a bug, that's just how it is 😭

πŸ”₯ optics2 method

EXPERIMENTAL β€” yes, experimental, tread carefully bestie. This method is similar to OPTICS, minimizing the reachability of each point. Points are reconnected if their reachability can be reduced. Contrary to OPTICS, a cluster's seed is not fixed but changed if possible. Each point is connected to another point until the core of the cluster (seed point) is reached. Effectively, the initial seed is updated in the process. Thus separated networks of points are created, with each network representing a cluster. The maximum distance is not used.


🧚 NOTES 🧚

By default, cluster IDs are stored as category values of the points in layer 2. remember that, it matters in literally every example below πŸ’–


⭐ EXAMPLE ⭐

Analysis of random points for areas in areas of the vector urbanarea (North Carolina sample dataset).

First generate 1000 random points within the areas the vector urbanarea and within the subregion, then do clustering and visualize the result:

# pick a subregion of the vector urbanarea
g.region -p n=272950 s=188330 w=574720 e=703090 res=10
# create random points in areas
v.random output=random_points npoints=1000 restrict=urbanarea
# identify clusters
v.cluster input=random_points output=clusters_optics method=optics
# set random vector color table for the clusters
v.colors map=clusters_optics layer=2 use=cat color=random
# display in command line
d.mon wx0
# note the second layer and transparent (none) color of the circle border
d.vect map=clusters_optics layer=2 icon=basic/point size=10 color=none

Figure: Four different methods with default settings applied to 1000 random points generated in the same way as in the example. Generate random points for analysis (100 points per area), use different method for clustering and visualize using color stored the attribute table.

# pick a subregion of the vector urbanarea
g.region -p n=272950 s=188330 w=574720 e=703090 res=10
# create clustered points
v.random output=rand_clust npoints=100 restrict=urbanarea -a
# identify clusters
v.cluster in=rand_clust out=rand_clusters method=dbscan
# create colors for clusters
v.db.addtable map=rand_clusters layer=2 columns="cat integer,grassrgb varchar(11)"
v.colors map=rand_clusters layer=2 use=cat color=random rgb_column=grassrgb
# display with your preferred method
# remember to use the second layer and RGB column
# for example use
d.vect map=rand_clusters layer=2 color=none rgb_column=grassrgb icon=basic/circle

🌈 SEE ALSO 🌈

r.clump, v.hull, v.distance β€” go read those too, they're the friend group πŸ’œ

🫢 AUTHOR 🫢

Markus Metz

πŸ’– SOURCE CODE πŸ’–

Available at: v.cluster source code (history)

Latest change: Wednesday May 07 13:01:38 2025 in commit: f20dbc611e2caa7b8ef368c71d9f0452fe5940eb

Main index | Vector index | Topics index | Keywords index | Graphical index | Full index


and that's a wrap, bestie πŸ’… this whole thing is Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual, and this page is literally v.cluster(1grass) from GRASS 8.5.0. go forth, cluster some points, and remember: layer 2. periodt. πŸ‘‘

πŸ“¦ where this page comes from