i want to change the resolution of elevation data for several countries and them merge those in one rasterlayer. I use getData function from raster package. I tried this one:
library(raster)
library(dplyr)
library(purrr)
eu = c("Italy","Spain")
eu_alt = eu %>%
map(~ {.x = getData("alt", country = .x)}) %>% # Get elevation
map(~ aggregate(.x, fact=5, fun=mean)) %>% # Change the resolution
map(~ as.data.frame(.x, xy=TRUE)) %>% # Convert to df
map(~ na.omit(.x)) %>% # Omit NA
reduce(full_join, by=c("x","y")) # Merge df
eu_alt = rasterFromXYZ(eu_alt)
But it does not work right; converting to dataframe does not seem to be the right approach. What i want is to get something like that:
class : RasterBrick
dimensions : 1417, 79993, 113350081, 2 (nrow, ncol, ncell, nlayers)
resolution : 0.0003472222, 0.008333333 (x, y)
extent : -9.296007, 18.47934, 35.29167, 47.1 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : in memory
names : ITA_msk_alt, ESP_msk_alt
min values : -5.72, -4.00
max values : 3972.077, 2919.840
i mean a rasterlayer with changed resolution where nlayers stand for country-specific data. What would be the easiest way to do it?
library(tidyverse)
, instead only call up packages you actually use. This looks like dplyr and purrr.