- 开始使用
- MEASUREMENT
- COORDINATE MUTATION
- TRANSFORMATION
- FEATURE CONVERSION
- MISC
- HELPER
- RANDOM
- DATA
- INTERPOLATION
- JOINS
- GRIDS
- CLASSIFICATION
- AGGREGATION
- META
- ASSERTIONS
- BOOLEANS
- UNIT CONVERSION
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
clusterReduce
Reduce clusters in GeoJSON Features, similar to Array.reduce()
简化GeoJSON要素中的聚类,类似于Array.reduce()
方法。
> npm install @turf/clusters
参数
参数 | 类型 | 描述 |
---|---|---|
geojson | FeatureCollection | GeoJSON Features |
property | (string|number) | GeoJSON property key/value used to create clusters |
callback | Function | a method that takes (previousValue, cluster, clusterValue, currentIndex) |
initialValue | (*) | Value to use as the first argument to the first call of the callback. |
返回
- The value that results from the reduction.
示例
var geojson = turf.featureCollection([
turf.point([0, 0]),
turf.point([2, 4]),
turf.point([3, 6]),
turf.point([5, 1]),
turf.point([4, 2])
]);
// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);
// Iterate over each cluster and perform a calculation
var initialValue = 0
turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue, currentIndex) {
//=previousValue
//=cluster
//=clusterValue
//=currentIndex
return previousValue++;
}, initialValue);
// Calculate the total number of clusters
var total = turf.clusterReduce(clustered, 'cluster', function (previousValue) {
return previousValue++;
}, 0);
// Create an Array of all the values retrieved from the 'cluster' property
var values = turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue) {
return previousValue.concat(clusterValue);
}, []);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论