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

边栏推荐
猜你喜欢

0. Quelques doutes au sujet de SolidWorks

Wrap dynamically created child elements in dynamically created structures

Buuctf web (III)

Vscode define code block -- define cursor position

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

Is signed or unsigned selected to create an integer field in MySQL? The answer is as follows:

Installing pytorch under Anaconda

Buffer Overflow Vulnerability Lab

Buuctf web (V)

关于RSA加密解密原理
随机推荐
regular expression
浅析Visual Studio 使用
Vscode double shortcut keys up, down, left and right
1. Learning sequence of SolidWorks modules
Journal d'acquisition du faisceau de fichiers à Elk
淘宝商品历史价格接口/商品历史价走势接口代码对接分享
\Difference between N and \r
À propos des principes de chiffrement et de décryptage RSA
Process and scheduled task management
Penetration problem (main directory, password explosion, database uploading Trojan horse)
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
Paging query template of Oracle
Namespace in TS (1)
JS wrapper object
A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
logstash配置参考文章
Review one flex knowledge point every day
JS to download files in batches
Batch package and download Alibaba OSS files
1、 JS introduction