Skip to main content
Version: 7.2.0

clustersKmeans

描述

¥Description

获取一组 points,并使用 K 均值聚类算法将其划分为不同的聚类。它使用 K 均值算法

¥Takes a set of points and partition them into clusters using the k-mean . It uses the k-means algorithm

参数

¥Parameters

名称类型描述
pointsFeatureCollection<>待聚类
options?对象可选参数(默认 {})
options.numberOfClusters?number将生成的簇数(默认值 Math.sqrt(numberOfPoints/2))
options.mutate?boolean允许 GeoJSON 输入发生修改(如果为 true,则性能显著提升)(默认为 false)

返回

¥Returns

FeatureCollection<> 聚类点,每个要素具有两个附加属性:

¥FeatureCollection<Point> Clustered Points with an additional two properties associated to each Feature:

  • ---左括号---数字---右括号--- 簇 - 关联的 clusterId

    ¥{number} cluster - the associated clusterId

  • ---左括号---[数字, 数字]---右括号--- 质心 - 聚类的质心 [经度,纬度]

    ¥{[number, number]} centroid - Centroid of the cluster [Longitude, Latitude]

示例

¥Examples

// create random points with random z-values in their properties
var points = turf.randomPoint(100, { bbox: [0, 30, 20, 50] });
var options = { numberOfClusters: 7 };
var clustered = turf.clustersKmeans(points, options);

安装

¥Installation

$ npm install @turf/clusters-kmeans

import { clustersKmeans } from "@turf/clusters-kmeans";
const result = clustersKmeans(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.clustersKmeans(...);