Warning
The application is not meant for external use. We will not answer support requests and might not address issues that don't affect us.
This API provides geospatial point clustering functionality. It groups geographical points based on their proximity, returning clustered points with assigned cluster IDs and sizes. The implementation uses Hono.js, Turf.js, and ml-hclust.
- Geospatial Point Clustering: Implements hierarchical clustering (Agglomerative Nesting) to group points within a specified distance limit, utilizing Turf.js for distance calculations.
- API Framework: Built with Hono.js.
- Language: Developed in TypeScript for type safety.
- Benchmarking: Includes a script for performance evaluation against a local or remote server.
- Hono.js
- Turf.js
- ml-hclust
- TypeScript
- tsx
- Node.js (v18 or higher recommended)
- pnpm (or npm/yarn)
- Clone the repository:
git clone https://github.com/your-username/geo-cluster-api.git cd geo-cluster-api - Install dependencies:
pnpm install
To start the development server:
pnpm startThe API will be running on http://localhost:3000.
Clusters a collection of GeoJSON Point features based on a specified distance limit.
- Method:
POST - URL:
http://localhost:3000/cluster - Headers:
Content-Type: application/json
- Body: A JSON array containing two elements:
geojson: A GeoJSONFeatureCollectionofPointfeatures.distance: A number representing the maximum distance (in kilometers) between points to be considered part of the same cluster.
Example Request Body:
[
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.0, 20.0]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.5, 20.5]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [50.0, 60.0]
}
}
]
},
100
]- Status:
200 OKon success,400 Bad Requestifgeojsonordistanceare missing,500 Internal Server Erroron other errors. - Body: A GeoJSON
FeatureCollectionofPointfeatures. Each feature will have additionalproperties:cluster: (Optional) A number representing the ID of the cluster the point belongs to. Present only if the point is part of a cluster with more than one point.clusterSize: (Optional) A number representing the total number of points in the cluster. Present only if the point is part of a cluster with more than one point.
Example Response Body:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"cluster": 0,
"clusterSize": 2
},
"geometry": {
"type": "Point",
"coordinates": [10.0, 20.0]
}
},
{
"type": "Feature",
"properties": {
"cluster": 0,
"clusterSize": 2
},
"geometry": {
"type": "Point",
"coordinates": [10.5, 20.5]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [50.0, 60.0]
}
}
]
}The project includes a benchmarking script to evaluate the performance of the clustering API.
To run the benchmark:
pnpm benchmarkYou can configure the benchmark to test against a local server or a remote server by modifying src/benchmark.ts:
// src/benchmark.ts
const USE_LOCAL_SERVER = false; // Set to true to test local, false for remote
const REMOTE_SERVER_URL = 'https://geo-cluster-api.vercel.app'; // Replace with your remote server URL