gpt4 book ai didi

r - 传单.extras : measure distance in metres

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

我想创建一个 map ,可以交互式地测量两点之间的距离。幸运的是,leaflet.extras 正是我所需要的,但是,我正在努力让它以(或公里)而不是英尺为单位生成输出。

考虑下面的代码:

library(leaflet)
library(leaflet.extras)
leaflet() %>%
addTiles() %>%
addDrawToolbar(
editOptions=editToolbarOptions(selectedPathOptions=selectedPathOptions())
)

它创建以下 map : enter image description here

但是,this示例( block 3)实际上使用相同的代码来创建相同的测量工具(折线),只不过它在 KM 中工作,而我的示例在英尺中工作。

如果您有任何可以帮助我切换到米而不是英尺的提示,我将非常感激。

最佳答案

drawPolylineOptions 函数不允许设置选项 feet=FALSE
因此,我建议修改 drawPolylineOptions 如下:

library(leaflet)
library(leaflet.extras)

mydrawPolylineOptions <- function (allowIntersection = TRUE,
drawError = list(color = "#b00b00", timeout = 2500),
guidelineDistance = 20, metric = TRUE, feet = FALSE, zIndexOffset = 2000,
shapeOptions = drawShapeOptions(fill = FALSE), repeatMode = FALSE) {
leaflet::filterNULL(list(allowIntersection = allowIntersection,
drawError = drawError, guidelineDistance = guidelineDistance,
metric = metric, feet = feet, zIndexOffset = zIndexOffset,
shapeOptions = shapeOptions, repeatMode = repeatMode)) }

leaflet() %>% setView(10.975342,45.421588,9) %>%
addTiles() %>%
addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
addDrawToolbar(
polylineOptions = mydrawPolylineOptions(metric=TRUE, feet=FALSE),
editOptions=editToolbarOptions(selectedPathOptions=selectedPathOptions())
)

enter image description here

此外,使用 addMeasures 您可以向 map 添加一个有用的工具来测量距离(请参阅 map 右上角的图标)。
可以通过 primaryLengthUnit 选项指定用于显示长度结果的单位。

leaflet() %>% setView(10.975342,45.421588,9) %>%
addTiles() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addDrawToolbar(
editOptions=editToolbarOptions(selectedPathOptions=selectedPathOptions())
) %>%
addMeasure(primaryLengthUnit="kilometers", secondaryLengthUnit="kilometers")

enter image description here

关于r - 传单.extras : measure distance in metres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46784533/

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