Supercluster
A high-performance Rust crate for geospatial and non-geospatial point clustering.
This crate was initially inspired by Mapbox's supercluster blog post.
Reference implementation

Features
-
load(points): Loads a FeatureCollection Object. Each feature should be a Feature Object. -
get_clusters(bbox, zoom): For the givenbboxarray ([west_lng, south_lat, east_lng, north_lat]) andzoom, returns an array of clusters and points as Feature Object objects. -
get_tile(z, x, y): For a given zoom and x/y coordinates, returns a FeatureCollection Object. -
get_children(cluster_id): Returns the children of a cluster (on the next zoom level) given its id (cluster_idvalue from feature properties). -
get_leaves(cluster_id, limit, offset): Returns all the points of a cluster (given itscluster_id), with pagination support. -
get_cluster_expansion_zoom(cluster_id): Returns the zoom on which the cluster expands into several children (useful for "click to zoom" feature) given the cluster'scluster_id.
Options
| Option | Description |
|---|---|
min_zoom |
Minimum zoom level at which clusters are generated. |
max_zoom |
Maximum zoom level at which clusters are generated. |
min_points |
Minimum number of points to form a cluster. |
radius |
Cluster radius, in pixels. |
extent |
(Tiles) Tile extent. Radius is calculated relative to this value. |
node_size |
Size of the KD-tree leaf node. Affects performance. |
coordinate_system |
Type of coordinate system for clustering. |
Safety
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
Documentation
For more in-depth details, please refer to the full documentation.
If you encounter any issues or have questions that are not addressed in the documentation, feel free to submit an issue.
Usage
Run the following Cargo command in your project directory:
use FeatureCollection;
use ;
Contributing
Contributions from the community are always welcome! Here are some ways you can contribute:
Reporting Bugs
If you encounter any bugs, please submit an issue with detailed information about the problem and steps to reproduce it.
Feature Requests
If you have ideas for new features, feel free to submit an issue with a detailed description of the feature and its potential use cases.
Build
To build the project, run:
Test
To run the tests, use:
Lint
Run clippy to lint the code:
Format
Run rustfmt to format the code:
Documentation
Generate documentation in HTML format:
