下载特定区域的卫星地图 - R.

时间:2018-03-22 14:32:32

标签: r import spatial ggmap sp

我对SpatialPointsDataFrame中汇总的点进行了总和分析:

> trjct_pts
class       : SpatialPointsDataFrame 
features    : 104559 
extent      : 696621.4, 696688.7, 167659.2, 167739.8  (xmin, xmax, ymin, ymax)
coord. ref. : +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 
variables   : 1
names       : Intensity_kJ 
min values  :      161.951 
max values  :     1192.526 

我曾经用它来创建2个栅格:

library(raster)
  rockfall_count <- 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")
  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")

  # count unique ID per raster 
  rockfall_count <- rasterize(trjct_points_coords, rockfall_count, fun = "count", by = ID)
  rockfall_count 
  plot(rockfall_count,col=brewer.pal(9,"YlOrRd"))


  # 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"))

为了好的插图,我想下载相应的卫星图像。我尝试过以下方法:

library(rgdal)
longlatcoor<-spTransform(trjct_pts,CRS("+proj=longlat"))
coordinates(longlatcoor)
longlatcoor 

library(ggmap)
library(ggplot2)

# Set a range
lat <- c(-13.4003, -13.39943)                
lon <- c(35.419, 35.41961)   

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

#limit lon and lat.      
tschamut <- ggmap(map)+
  scale_x_continuous(limits = c(-13.4003, -13.39943), expand = c(0, 0)) +
  scale_y_continuous(limits = c(35.419, 35.41961), expand = c(0, 0))
tschamut

然而,每当我尝试运行此代码时R都会崩溃,所以我怀疑它有严重错误。我从边界框中导出了代码中使用的数字:

> longlatcoor
class       : SpatialPointsDataFrame 
features    : 104559 
extent      : -13.4003, -13.39943, 35.419, 35.41961  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 
variables   : 1
names       : Intensity_kJ 
min values  :      161.951 
max values  :     1192.526 

如何将航拍照片导入R?

0 个答案:

没有答案