【问题标题】:R Draw Circle with Radius (r metres) in Lat/Lon (epsg 4326)R在纬度/经度中绘制半径(r米)的圆(epsg 4326)
【发布时间】:2015-12-17 16:33:04
【问题描述】:

我想在我的数据集中为大约 100 个点创建一个缓冲区,该缓冲区的长度为 r,并且在点之间变化(基本上这是客户愿意前往该点/商店的 80% 的距离) .

我的数据包含以下列:lat_centre、lon_centre、radius_km

这是一个 1 公里的例子:

Javascript 与谷歌地图。

   var draw_circle = new google.maps.Circle({
        center: point_i,
        radius: 1000,
        strokeColor: col,
        strokeOpacity: 0.15,
        strokeWeight: 2,
        fillColor: col,
        fillOpacity: 0.15,
        map: map
    });

在左边绘制图像:

但是,下面的 R 尝试在右边画了一个圆圈(你可以看到它更小):

library(dismo)
emory <- gmap("Bishopsgate, London", zoom = 14, scale = 2)
d <- data.frame(lat = c(51.51594), lon = c(-0.08248))
coordinates(d) <- ~ lon + lat
projection(d) <- "+init=epsg:4326"

mm <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
d_mrc <- spTransform(d, CRS = CRS(mm))

# Buffer creation
d_mrc_bff <- gBuffer(d_mrc, width = 1000)
library(scales) # for `alpha()` function

plot(emory)
plot(d_mrc_bff, col = alpha("red", .35), add = TRUE)
points(d_mrc, cex = 2, pch = 20)

【问题讨论】:

标签: r geometry latitude-longitude


【解决方案1】:

我已经编写了 googleway 包来访问 Google Maps Javascript API,因此您可以复制您的图像。

为此,您需要一个有效的 Google API 密钥

library(googleway)

## your api key 
map_key <- "your_api_key_goes_here"

d <- data.frame(lat = c(51.51594), lon = c(-0.08248))

google_map(data = d, key = map_key, height = 800) %>%
    add_markers() %>%
    add_circles(radius = 1000)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多