当前位置:网站首页>JS to realize the calculation of discrete aggregation points
JS to realize the calculation of discrete aggregation points
2022-06-25 11:57:00 【GIS roast lamb leg is delicious】
explain
This example uses Turf.js Inside clustersDbscan class , He aggregates according to the distance between adjacent points , When the distance is less than the specified distance, it will converge , Generally, the introduction of front-end map rendering components does not require self calculation , This method combines echarts Better rendering .
advantage : Simple , Aggregate directly through distance .
shortcoming : After thousands of quantity sets, it will lead to Caton . Optimization plan , Batch polymerizable , Per aggregation 300 strip , Finally, the results of each aggregation are aggregated twice , This can withstand tens of thousands of points . But the error will be large .
turf.js download
npm install @turf/turf
Code block
import * as turf from '@turf/turf'
var points={
type: "FeatureCollection",
features:[
{type: "Feature",geometry:{ type: "Point",coordinates:[123.4,33.9] } },
{type: "Feature",geometry:{ type: "Point",coordinates:[123.5,33.9] } },
{type: "Feature",geometry:{ type: "Point",coordinates:[96.4,20.9] } },
{type: "Feature",geometry:{ type: "Point",coordinates:[120.4,38.9] } },
{type: "Feature",geometry:{ type: "Point",coordinates:[123.4,33.9] } },
{type: "Feature",geometry:{ type: "Point",coordinates:[123.4,33.9] } },
]
}
var clustered= turf.clustersDbscan(points, 100);// The default unit is kilometers
var arr = clustered.features; // The returned data is marked with characteristics .
var ary={};
/* Remove the weight and count the quantity */
for(let i=0;i<arr.length;i++){
var x=arr[i].properties.centroid[0];
var y=arr[i].properties.centroid[1];
if(arr[i].properties.cluster!=undefined){
if(arr[i].properties.cluster in ary){
ary[arr[i].properties.cluster]=[x,y,ary[arr[i].properties.cluster][2]+1];// Duplicate quantity +1
}else{
ary[arr[i].properties.cluster]=[x,y,1];// The default quantity without repetition is one
}
}else{
ary[arr[i].properties.centroid]=[x,y,1];// The default quantity without repetition is one
}
}
// The final results pointResult
var pointResult=[]
for( var key in ary){
pointResult.push({
name:ary[key][2],
value:ary[key]
})
}
console.log(pointResult)
边栏推荐
- Ladder side tuning: the "wall ladder" of the pre training model
- VFP calls the command line image processing program, and adding watermark is also available
- Windows11 MySQL service is missing
- Keywords serializable serialization and deserialization
- A detour taken by a hardware engineer
- 黑马畅购商城---2.分布式文件存储FastDFS
- Use of JSP sessionscope domain
- 分享7个神仙壁纸网站,让新的壁纸,给自己小小的雀跃,不陷入年年日日的重复。
- Specific meanings of node and edge in Flink graph
- Share 7 immortal wallpaper websites, let the new wallpaper give you a little joy, and don't fall into the repetition year after year.
猜你喜欢
SQL injection vulnerability (type chapter)
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed
ROS 笔记(06)— 话题消息的定义和使用
Old ou, a fox friend, has had a headache all day. The VFP format is always wrong when it is converted to JSON format. It is actually caused by disordered code
架构师为你揭秘在阿里、腾讯、美团工作的区别
Redis雪崩、穿透和击穿是什么?
Customize to prevent repeated submission of annotations (using redis)
Hangzhou / Beijing neitui Ali Dharma academy recruits academic interns in visual generation (talent plan)
Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit
Oracle Spatial creating spatial tables
随机推荐
Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit
黑马畅购商城---3.商品管理
VFP calls the command line image processing program, and adding watermark is also available
quarkus saas动态数据源切换实现,简单完美
Introduction to JVM principle
芯片的发展史和具体用途以及结构是什么样的
Where do the guests come from
Nacos installation and use
Continue to cut the picture after the ArcGIS Server is disconnected
客从何处来
一個硬件工程師走過的彎路
ROS 笔记(06)— 话题消息的定义和使用
Flink deeply understands the graph generation process (source code interpretation)
揭秘GaussDB(for Redis):全面对比Codis
SQL server saves binary fields to disk file
Mui scroll bar recovery
How far is it from the DBF of VFP to the web salary query system?
Which securities company's account is better and safer to open
Thirty lines of code prevent VFP forms from running repeatedly, and the function supports parameter transfer
Translation of meisai C topic in 2022 + sharing of ideas