gpt4 book ai didi

r - 获取指定边界坐标的 map

转载 作者:行者123 更新时间:2023-12-03 13:20:01 26 4
gpt4 key购买 nike

我想从 R 获取带有 RgoogleMaps 的 map ,具有特定的坐标边界。

我可以调用的是GetMap,并指定一个中心,我必须添加一个缩放级别。一切正常,除了我没有得到一个以我选择的坐标为界的图像 map 。

这是一个例子:

lat <- c(44.49,44.5)                
lon <- c(11.33,11.36)
center = c(mean(lat), mean(lon))
zoom <- 14
mmap <- GetMap(center = center, zoom=zoom, maptype= "satellite", destfile = "m.png")

问题是只有中心作为参数传递,因此我看到的整个图像取决于缩放级别。所以,我无法真正理解我得到的图像的边界是什么。我想要做的是得到一个与我定义的坐标完全一致的图像。这可能吗(也可以使用其他 map 包)?

最佳答案

这是一种方法。首先,您会得到一张具有一定缩放比例的 map 。然后,在绘制图形时添加 lon 和 lat 限制,您可以使用 scale_x_continuousscale_y_continuous .

library(ggmap)
library(ggplot2)

### Set a range
lat <- c(44.49, 44.5)
lon <- c(11.33, 11.36)

### Get a map
map <- get_map(location = c(lon = mean(lon), lat = mean(lat)), zoom = 14,
maptype = "satellite", source = "google")

### When you draw a figure, you limit lon and lat.
foo <- ggmap(map)+
scale_x_continuous(limits = c(11.33, 11.36), expand = c(0, 0)) +
scale_y_continuous(limits = c(44.49, 44.5), expand = c(0, 0))

foo

enter image description here

关于r - 获取指定边界坐标的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25636897/

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