fid*_*est 3 javascript geojson turfjs
我正在尝试从中心点和半径生成 p 方形多边形。就像下面这样。
bboxPolygon(square(bbox(circle(_circle.center, 0.5, { steps: 64 }))))
Run Code Online (Sandbox Code Playgroud)
所有功能均来自turf.js
我相信这应该生成完美的正方形或至少接近正方形。但是,它返回矩形。
我不确定这是草皮库问题还是我使用错误。
圆形 geojson
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-73.93524199999999,
40.734656941636764
],
[
-73.93791238162646,
40.73411472349626
],
[
-73.93986713367875,
40.73263337851494
],
[
-73.94058248193825,
40.730609876934174
],
[
-73.93986685239045,
40.72858643688632
],
[
-73.93791210033818,
40.72710521497083
],
[
-73.93524199999999,
40.72656305836324
],
[
-73.93257189966181,
40.72710521497083
],
[
-73.93061714760952,
40.72858643688632
],
[
-73.92990151806174,
40.730609876934174
],
[
-73.93061686632124,
40.73263337851494
],
[
-73.93257161837353,
40.73411472349626
],
[
-73.93524199999999,
40.734656941636764
]
]
]
}
}
Run Code Online (Sandbox Code Playgroud)
bboxPolygon 结果
{
"type": "Feature",
"bbox": [
-73.93928894163675,
40.72656305836324,
-73.93119505836323,
40.734656941636764
],
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-73.93928894163675,
40.72656305836324
],
[
-73.93119505836323,
40.72656305836324
],
[
-73.93119505836323,
40.734656941636764
],
[
-73.93928894163675,
40.734656941636764
],
[
-73.93928894163675,
40.72656305836324
]
]
]
}
}
Run Code Online (Sandbox Code Playgroud)
我认为问题出在turf.square功能上。它没有达到我的预期。
如果你替换你应该得到非常接近正方形的东西
bboxPolygon(square(bbox(circle(_circle.center, 0.5, { steps: 64 }))))
和
bboxPolygon(bbox(circle(_circle.center, 0.5, { steps: 64 })))
下面是输出的示例。红色是圆形,绿色是使用正方形得到的输出,蓝色是不使用正方形得到的输出。
如果你查看源代码,你square会发现它实际上并没有创建一个每边距离相等的 bbox。然而,它创建了一个具有相同程度变化的bbox。由于我们正在处理经度和纬度,因此通常不是距离为正方形的多边形。
我不确定为什么有人需要这个square函数,因为如果它的距离是平方的,我会发现它更有用,但我不知道这是否是预期的行为。
TLDR
尝试bboxPolygon(bbox(circle(_circle.center, 0.5, { steps: 64 })))一下
| 归档时间: |
|
| 查看次数: |
3005 次 |
| 最近记录: |