DevCrew.SuperCluster
1.0.0
See the version list below for details.
dotnet add package DevCrew.SuperCluster --version 1.0.0
NuGet\Install-Package DevCrew.SuperCluster -Version 1.0.0
<PackageReference Include="DevCrew.SuperCluster" Version="1.0.0" />
paket add DevCrew.SuperCluster --version 1.0.0
#r "nuget: DevCrew.SuperCluster, 1.0.0"
// Install DevCrew.SuperCluster as a Cake Addin #addin nuget:?package=DevCrew.SuperCluster&version=1.0.0 // Install DevCrew.SuperCluster as a Cake Tool #tool nuget:?package=DevCrew.SuperCluster&version=1.0.0
SuperCluster-CSharp
A C# library that provides an efficient way to cluster large point datasets. This library is based on the popular SuperCluster JavaScript library by Mapbox and has been optimized for performance in .NET environments. It helps to implement clustering feature in Unity3d WebGL and in any .NET framework.
Installation
Install using NuGet
We'll soon publish our library to NuGet Packages Gallery and then you can search for DevCrew.SuperCluster or SuperCluster on NuGet package manager in Visual Studio and add it to your project.
Install as open source
The second option is to add SuperCluster as an open source module to your .NET or Unity project if you don't use NuGet.
- Clone the repo
https://github.com/DevCrew-io/SuperCluster-CSharp.git
- Make sure to checkout
main
branch - Copy the
DevCrew.SuperCluster
folder and removeDevCrew.SuperCluster.csproj
file - Now Paste the whole DevCrew.SuperCluster package into your project and you are ready to use
Usage
GeoPoint
Map your data set into list of GeoPoint
private readonly List<GeoPoint> _points = new List<GeoPoint>();
//here we have added some dummy geo coordinates
_points.Add(new GeoPoint(longitude: -112.8384399, latitude: 49.696595));
_points.Add(new GeoPoint(longitude: -112.838563, latitude: 49.694496));
_points.Add(new GeoPoint(longitude: -112.8412346, latitude: 49.696189));
Options
Create a new object of SuperCluster
with clustering options
//superCluster with default clustering options
private readonly SuperCluster _superCluster = new(options: SuperCluster.DefaultOptions);
//or you can provide your own clustering options like this:
Options customOptions = new(
minZoom: 0,
maxZoom: 16,
minPoints: 2,
radius: 30,
extent: 512,
nodeSize: 64,
log: true,
generateId: false
);
Option | Default | Description |
---|---|---|
minZoom | 0 | Minimum zoom level at which clusters are generated |
maxZoom | 16 | Maximum zoom level at which clusters are generated |
minPoints | 2 | Minimum number of points to form a cluster |
radius | 40 | Cluster radius, in pixels |
extent | 512 | (Tiles) Tile extent. Radius is calculated relative to this value |
generateId | false | Whether to generate ids for input features in vector tiles |
nodeSize | 64 | Size of the KD-tree leaf node. Affects performance |
log | false | Whether timing info should be logged |
Methods
Load(points)
Once we have create a super cluster object then we can cluster our points using Load()
method. It creates all possible clusters for different zoom levels at once.
//This method should be called only once
_superCluster.Load(points: _points);
GetClusters(bbox, zoom)
For the given bbox array [westLng, southLat, eastLng, northLat]
and integer zoom
, returns an array of clusters and points.
var bbox = new double[] { -180, -85, 180, 85 };
//This method should be called on zoom in and zoom out events.
var clusterData = _superCluster.GetClusters(bbox: bbox, zoom: 16);
Console.WriteLine("clusterData.count: " + clusterData.Count);
//print clustered data
foreach (var output in clusterData.Select(JsonConvert.SerializeObject))
{
Console.WriteLine(output);
}
//you can filter between clusters and individual points from clusterData output like this
foreach (var geoJsonFeature in clusterData)
{
if (geoJsonFeature is GeoPoint)
{
//This is single geo point
}
else
{
//This is a cluster
}
}
Authors
Waseem Abbas (Software Engineer at DevCrew.IO)
Connect with Us
<p align="left"> <a href="https://devcrew.io" target="blank"><img align="center" src="https://devcrew.io/wp-content/uploads/2022/09/logo.svg" alt="devcrew.io" height="35" width="35" /></a> <a href="https://www.linkedin.com/company/devcrew-io/mycompany/" target="blank"><img align="center" src="https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/linked-in-alt.svg" alt="mycompany" height="30" width="40" /></a> <a href="https://www.facebook.com/devcrew.io" target="blank"><img align="center" src="https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/facebook.svg" alt="devcrew.io" height="30" width="40" /></a> <a href="https://www.instagram.com/devcrew.io" target="blank"><img align="center" src="https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/instagram.svg" alt="devcrew.io" height="30" width="40" /></a> <a href="https://github.com/DevCrew-io" target="blank"><img align="center" src="https://cdn-icons-png.flaticon.com/512/733/733553.png" alt="DevCrew-io" height="32" width="32" /></a> </p>
Contributing
Contributions, issues, and feature requests are welcome!
Show your Support
Give a star if this project helped you.
Copyright & License
Code copyright 2023–2024 DevCrew I/O. Code released under the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- NGeoKDBush (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
initial release