R:导入特定区域的卫星图像

时间:2018-03-17 21:43:19

标签: r maps spatial raster

根据模拟数据,我创建了指示危险的栅格文件,即危险图:

      library(raster)
  rockfall_intensity <- raster (xmn = 696583.6, xmx = 696799.6, ymn = 167579.6, ymx = 167789.6, res = 2,
                                  crs = "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs")

  # average kinetic energy per raster cell
  rockfall_intensity <- rasterize(trjct[, c('x', 'y')], rockfall_intensity, trjct$Etot, fun = mean)
  plot(rockfall_intensity, col=brewer.pal(9,"YlOrRd"))

enter image description here

我想下载此区域的卫星图像(并将栅格固定在顶部)。我查看了get_map函数

  ??get_map
  mapImageData3 <- get_map(location = c(lon = -7.439583333333333, lat = 46.95240555555556),
                           color = "color",
                           source = "google",
                           maptype = "roadmap",
                           zoom = 16)

  ggmap(mapImageData3,
        extent = "device",
        ylab = "Latitude",
        xlab = "Longitude")

Theme element panel.border missing
Error in if (theme$panel.ontop) { : argument is of length zero
In addition: Warning message:
`panel.margin` is deprecated. Please use `panel.spacing` property instead 

如何修复错误? 这有更好的方法吗?

我希望得到一张颜色映射,例如: enter image description here

1 个答案:

答案 0 :(得分:1)

这里有一些问题:

  1. 您所在的位置位于海洋中央。您以非常高的缩放比例选择路线图。所以你只会看到蓝色。
  2. 使用maptype =&#34; satellite&#34;如果您想要在上面的照片中显示的那种地图,以及更小的缩放。
  3. 如果您想实际看到标签(而不是获得警告),请为范围选择其他值。
  4. 例如:

    mapImageData3 <- get_map(location = c(lon = -7.43958, lat = 46.95241),
                             color = "color", source = "google", 
                             maptype = "satellite", zoom = 7)
    ggmap(mapImageData3, extent = "normal", ylab = "Lattitude", 
          xlab = "Longitude")