当前位置:网站首页>turf. JS usage
turf. JS usage
2022-06-13 08:44:00 【Dependency_ Lai】
1. stay index.html Direct reference
<script src="https://unpkg.com/@turf/[email protected]/turf.min.js"></script>
2. Use directly where necessary turf object ,turf It is mainly used to calculate the relationship between spatial geometric objects , spot 、 Line 、 Include between faces 、 Intersection and other systematic operations .
Please refer to turf.js Chinese net :https://turfjs.fenxianglu.cn/category/#cdn%E5%BC%95%E5%85%A5
3. Determine whether the point is within the polygon range
let pt = turf.point([103.30749303102493, 29.789869635742235]);
let coordinates = [...];// Polygon data
let poly;
if(coordinates.length>1){
// solve 'Each LinearRing of a Polygon must have 4 or more Positions.' error
poly = turf.multiPolygon(coordinates);
}else{
poly = turf.polygon(coordinates);
}
let isIncluded = turf.booleanPointInPolygon(pt, poly)
Polygon data format :

3. Get the center point of the polygon range
let poly;
let coordinates = [...];// Polygon data
if(coordinates.length>1){
// solve 'Each LinearRing of a Polygon must have 4 or more Positions.' error
poly = turf.multiPolygon(coordinates );
}else{
poly = turf.polygon(coordinates );
}
let centerPoint = turf.centerOfMass(poly); // Get the coordinates of the center point of the polygon
console.log(centerPoint)

4. Get a series of points and the absolute center point of the polygon
let areaArr = areaData.map(item=>item.geometry.coordinates);
let pointArr = pointData.map(item=>item.geometry.coordinates);
let centerPoint;
if(areaArr.length){
centerPoint = turf.centroid(turf.multiPolygon([...areaArr, ...pointArr]))
}else{
centerPoint = turf.center(turf.featureCollection(
pointArr.map(item=>turf.point(item))
))
}
let areaCoordinates = [...];// Polygon data
let pointCoordinates = [...];// Point data
let centerPoint;
if(areaCoordinates.length){
// Determine whether there are polygons
centerPoint = turf.centroid(turf.multiPolygon([...areaCoordinates , ...pointCoordinates ]))
}else{
centerPoint = turf.center(turf.featureCollection(
pointCoordinates.map(item=>turf.point(item))
))
}
console.log(centerPoint)

边栏推荐
- MySQL sorts according to the specified order of the specified fields
- Browser render passes
- Bidirectional retransmission step experiment
- JS - array de duplication in the array object case
- 0.一些自己初學Solidworks的疑惑
- Installing pytorch under Anaconda
- When submitting the laravel admin form and using the required verification, an error is reported when the value is 0
- Review one flex knowledge point every day
- Wechat upload picture material interface
- Penetration problem (main directory, password explosion, database uploading Trojan horse)
猜你喜欢

Docker installing MySQL local remote connection docker container MySQL
![[pychart pit stepping record] prompt after configuring remote operation, [errno 2] no such file or directory](/img/71/92c06496a9d982294cac61595e0392.png)
[pychart pit stepping record] prompt after configuring remote operation, [errno 2] no such file or directory

A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)

4、 Js-es5-i / O

0. Quelques doutes au sujet de SolidWorks

DHCP principle and configuration

À propos des principes de chiffrement et de décryptage RSA

CentOS installing MySQL and setting up remote access

MySQL parsing serialized fields

MySQL queries difference sets (missing data) by linking tables based on an associated field
随机推荐
GBase 8a V95与V86压缩策略类比
PHP PNG to webp
How app inventor accesses resource files in assets directory
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
filebeat采集日志到ELK
淘宝商品销量接口/淘宝商品销量监控接口/商品累计销量接口
Emotion handling skills
Bidirectional retransmission step experiment
Vscode define code block -- define cursor position
0. Quelques doutes au sujet de SolidWorks
MySQL queries difference sets (missing data) by linking tables based on an associated field
8、 JS data type conversion
GBase 常见网络问题及排查方法
Container concept and cloud native
3、 JS notes
MySQL sorts according to the specified order of the specified fields
Buffer Overflow Vulnerability Lab
Process and scheduled task management
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
Taobao commodity historical price interface / commodity historical price trend interface code docking and sharing