Skip to content

KBE3D / KBCore / turf / getCluster

函数: getCluster()

getCluster<G, P>(geojson: FeatureCollection<G, P>, filter: any): FeatureCollection<G, P>

Function

Get Cluster

类型参数

G

G extends Geometry

P

P extends GeoJsonProperties = GeoJsonProperties

参数

geojson

FeatureCollection<G, P>

GeoJSON Features

filter

any

Filter used on GeoJSON properties to get Cluster

返回

FeatureCollection<G, P>

Single Cluster filtered by GeoJSON Properties

示例

ts
var geojson = turf.featureCollection([
    turf.point([0, 0], {'marker-symbol': 'circle'}),
    turf.point([2, 4], {'marker-symbol': 'star'}),
    turf.point([3, 6], {'marker-symbol': 'star'}),
    turf.point([5, 1], {'marker-symbol': 'square'}),
    turf.point([4, 2], {'marker-symbol': 'circle'})
]);

// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);

// Retrieve first cluster (0)
var cluster = turf.getCluster(clustered, {cluster: 0});
//= cluster

// Retrieve cluster based on custom properties
turf.getCluster(clustered, {'marker-symbol': 'circle'}).length;
//= 2
turf.getCluster(clustered, {'marker-symbol': 'square'}).length;
//= 1

KBE3D @3.0.0 Copyright © 2024-present KBE3D