gpt4 book ai didi

javascript - 使用 turf.intersect 时出现 TopologyException

转载 作者:行者123 更新时间:2023-12-02 02:51:19 27 4
gpt4 key购买 nike

将 turf.intersect 与特定多边形一起使用时,出现以下错误:“TopologyException”“发现 LINESTRING(-0.140733 51.505327、-0.141097 51.505689)和 LINESTRING(-0.141136 51.505674、-0.141068 51.5057)之间的非节点交集”

这是导致问题的点所在的多边形:

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-0.144414,
51.5057787
],
[
-0.1444,
51.5057669
],
[
-0.1444174,
51.5057565
],
[
-0.1444375,
51.5057437
],
[
-0.1444486,
51.5057591
],
[
-0.1448395,
51.5055465
],
[
-0.1456195,
51.5051519
],
[
-0.1461211,
51.5048921
],
[
-0.1467341,
51.5045993
],
[
-0.1472694,
51.5042539
],
[
-0.147728,
51.5039184
],
[
-0.1485316,
51.5035408
],
[
-0.1485702,
51.5035234
],
[
-0.1488964,
51.503376
],
[
-0.1489081,
51.5033859
],
[
-0.1491678,
51.503267
],
[
-0.1491573,
51.5032582
],
[
-0.1494585,
51.5031342
],
[
-0.1495505,
51.5031388
],
[
-0.1495754,
51.503085
],
[
-0.1496124,
51.5026853
],
[
-0.1495618,
51.5026316
],
[
-0.1495053,
51.5025839
],
[
-0.1490356,
51.5025596
],
[
-0.1480816,
51.5025194
],
[
-0.1464951,
51.5024587
],
[
-0.1453418,
51.5023882
],
[
-0.1444299,
51.5023513
],
[
-0.1424233,
51.502272
],
[
-0.1420358,
51.5022744
],
[
-0.1416246,
51.5022811
],
[
-0.1414344,
51.5022758
],
[
-0.14113,
51.5023094
],
[
-0.1409441,
51.50233
],
[
-0.1412107,
51.5026049
],
[
-0.1407386,
51.5026799
],
[
-0.1402814,
51.5026536
],
[
-0.1398146,
51.5025228
],
[
-0.1396726,
51.5024475
],
[
-0.1395941,
51.5023923
],
[
-0.1394956,
51.5024312
],
[
-0.1393765,
51.5024829
],
[
-0.1388305,
51.502698
],
[
-0.1387333,
51.5027403
],
[
-0.1387835,
51.5027906
],
[
-0.1392711,
51.5032406
],
[
-0.139465,
51.503466
],
[
-0.1399479,
51.5039078
],
[
-0.1403315,
51.504302
],
[
-0.1407059,
51.5046814
],
[
-0.1402579,
51.5048283
],
[
-0.1407332,
51.5053265
],
[
-0.1410967,
51.5056887
],
[
-0.1410841,
51.5056711
],
[
-0.1411158,
51.5056574
],
[
-0.1411356,
51.5056744
],
[
-0.141068,
51.5057001
],
[
-0.1411549,
51.5058139
],
[
-0.1412316,
51.5057886
],
[
-0.1412437,
51.5058054
],
[
-0.1411693,
51.5058326
],
[
-0.1411811,
51.5058428
],
[
-0.1412021,
51.5058461
],
[
-0.1412326,
51.5058618
],
[
-0.1412584,
51.5058575
],
[
-0.1413349,
51.5059475
],
[
-0.1413677,
51.5059833
],
[
-0.1413704,
51.5060066
],
[
-0.1413538,
51.506016
],
[
-0.1413494,
51.5060451
],
[
-0.1414301,
51.5061301
],
[
-0.1414221,
51.5061562
],
[
-0.1414889,
51.5062259
],
[
-0.1415374,
51.5062089
],
[
-0.1415669,
51.506238
],
[
-0.1415172,
51.5062553
],
[
-0.141583,
51.506326
],
[
-0.1416228,
51.5063353
],
[
-0.1416919,
51.5064173
],
[
-0.1416845,
51.5064298
],
[
-0.1416341,
51.5064488
],
[
-0.1416636,
51.5064833
],
[
-0.1416771,
51.5064797
],
[
-0.1416892,
51.5064881
],
[
-0.1418973,
51.5064092
],
[
-0.1419091,
51.5064204
],
[
-0.141691,
51.5065052
],
[
-0.1417355,
51.5065528
],
[
-0.1417624,
51.5065417
],
[
-0.1417862,
51.506569
],
[
-0.141812,
51.5065727
],
[
-0.141838,
51.5065954
],
[
-0.1418271,
51.5066109
],
[
-0.1418623,
51.5066435
],
[
-0.1418837,
51.5066417
],
[
-0.1419093,
51.5066617
],
[
-0.1419035,
51.5066764
],
[
-0.1419137,
51.5066845
],
[
-0.1419323,
51.506686
],
[
-0.1419469,
51.5067007
],
[
-0.1419413,
51.5067104
],
[
-0.1419583,
51.5067201
],
[
-0.1421823,
51.5066524
],
[
-0.1422288,
51.5066342
],
[
-0.1423373,
51.5067681
],
[
-0.1430385,
51.5064228
],
[
-0.143099,
51.5064704
],
[
-0.1439141,
51.5060467
],
[
-0.144414,
51.5057787
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-0.14109693591549397,
51.5056889362676
]
}
}
]
}

我尝试过使用 cleanCoords 并检查与扭结的交集,但它不起作用。

最佳答案

以下是我设法使其发挥作用的方法:

var options = {tolerance: 0.0001, highQuality: true};
poly = turf.cleanCoords(turf.simplify(poly, options));

我还检查了扭结,如果返回 true,则分割多边形:

var kinks = turf.kinks(poly);
if (kinks.features.length){
polys = turf.unkinkPolygon(poly);
...

关于javascript - 使用 turf.intersect 时出现 TopologyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61926747/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com