npm 包 @turf/clusters-dbscan 使用教程

阅读时长 6 分钟读完

介绍

@turf/clusters-dbscan 是一个由 Turf.js 开发的 npm 包,用于在地图上进行点聚类。该包使用 DBSCAN(Density-Based Spatial Clustering of Applications with Noise)算法实现。

安装

到项目目录中运行以下命令:

使用

导入

API

clustersDbscan(points, maxDistance, options?)

对给定的点进行聚类。

参数:

  • points(FeatureCollection<Point>),表示进行聚类的点集合。
  • maxDistancenumber,表示点与点之间可以互相连接的最大距离(单位:米)。
  • optionsObject,可选参数。可设置 { minPoints: number },表示处于簇中的最小点数,默认为 2。

返回:

FeatureCollection<Point, Properties & { cluster: number, noise: boolean }>

cluster 属性表示点所属的聚类(从 0 开始编号),如果为 -1,则表示该点为“噪点”(没有归属于任何聚类);noise 属性表示该点是否为噪点。

以下是一个聚类示例:

-- -------------------- ---- -------
----- ---- - ----------------------
----- -------------- - ---------------------------------

-- -----
----- ------ - ------------------------
  ----------------------- ------------
  ----------------------- ------------
  ---------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
  ----------------------- ------------
---

-- ----
----- ------ - ---------------------- ---- - ---------- - ---

-- ------
---------------------------------- ----- ----
展开代码

输出结果如下:

-- -------------------- ---- -------
-
  ------- --------------------
  ----------- -
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ----------- ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- --- -------- ---- --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- --- -------- ---- --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- - --
      ----------- - ------- -------- -------------- ------------ ---------- -
    --
    -
      ------- ----------
      ------------- - ---------- --- -------- ---- --
      ----------- - ------- -------- -------------- ------------ ---------- -
    -
  -
-
展开代码

总结

@turf/clusters-dbscan 是一个强大的点聚类工具,可以快速对地图上的点进行聚类。通过本教程,你可以掌握该工具的基本使用和常见参数的设置,希望对你的前端工作有所帮助。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/5eedae28b5cbfe1ea0610dae

纠错
反馈

纠错反馈