当前位置:网站首页>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)

边栏推荐
- Yarn package management tool
- Vscode define code block -- define cursor position
- Journal d'acquisition du faisceau de fichiers à Elk
- redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
- JS to download files in batches
- PHP isset() method ignores data error handling caused by null parameter value
- Vscode double shortcut keys up, down, left and right
- filebeat采集日志到ELK
- 淘宝商品历史价格接口/商品历史价走势接口代码对接分享
- HCIP_ OSPF irregular area
猜你喜欢

關於RSA加密解密原理

MySQL queries difference sets (missing data) by linking tables based on an associated field

Problems in the deconstruction and assignment of objects, comparison between empty strings and undefined

SQL injection experiment

Use of addeventlistener in JS

Wrap dynamically created child elements in dynamically created structures

JS array using the reduce() method

Wechat upload picture material interface

On the use of regular expressions (bracket problem)

Buuctf web (VII)
随机推荐
情绪处理技巧
淘宝商品历史价格接口/商品历史价走势接口代码对接分享
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
JS string method
LVM management exercise
redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
PHP isset() method ignores data error handling caused by null parameter value
Phpexcel 10008 error resolution
Logstash failed to create queue
JS - for cycle case: Horse grain
抖音关键词搜索列表接口,超详细的接口对接步骤
Taobao commodity historical price interface / commodity historical price trend interface code docking and sharing
GBase 8a磁盘问题及处理
Three methods to make the scroll bar of div automatically scroll to the bottom
Process and scheduled task management
JD commodity detail interface, JD detail page interface, baby detail page interface, commodity attribute interface, commodity information query, commodity detail interface, H5 details, JD app details,
6、 JS naming rules and specifications
About RSA encryption and decryption principle
Verify the word limit of textarea input box. Only prompt but no submission limit
Buuctf web (VI)