library(sf)
library(rgdal)
library(terra)
library(tmap)
library(dplyr)
library(magrittr)
library(purrr)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggplot2)
library(leaflet)
library(mapview)
library(grid)
library(ggmap)
library(basemaps)
library(raster)
library(rnaturalearthhires)
install.packages("basemaps")
setwd("E:/GIS_DATA/Glacier_Alaska_and_Western")
ak <- st_read("01_rgi60_Alaska.shp")
wes <- st_read("02_rgi60_WesternCanadaUS.shp")
ak
wes
str(ak)
str(wes)
st_crs(ak) == st_crs(wes)
st_bbox(ak) == st_bbox(wes)
tmap_options(check.and.fix = TRUE)
nwa_bbox <- st_bbox(
st_union(
st_as_sfc(st_bbox(wes)),
st_as_sfc(st_bbox(ak))
)
)
tm_shape(ak, bbox = nwa_bbox) +
tm_polygons()+
tm_shape(wes)+
tm_polygons()+
tm_layout(
title = "Glaciers of Western North America",
title.position = c("center", "top"),
title.size = 1.1,
bg.color = "#fcfcfc",
inner.margins = c(0.06, 0.01, 0.09, 0.01),
outer.margins = 0,
frame.lwd = 0.2
)+
tm_compass(
type = "arrow",
position = c("right", "top"),
size = 1.2,
text.size = 0.6
)+
tm_scale_bar(
breaks = c(0, 1000, 2000),
position = c("right", "BOTTOM")
)
states_all <- ne_states(
country = c("canada", "united states of america"),
returnclass = "sf"
)
states <- states_all %>%
filter(name_en == "Alaska" |
name_en == "British Columbia" |
name_en == "Yukon" |
name_en == "Northwest Territories" |
name_en == "Alberta" |
name_en == "California" |
name_en == "Washington" |
name_en == "Oregon" |
name_en == "Idaho" |
name_en == "Montana" |
name_en == "Wyoming" |
name_en == "Colorado"
)
st_crs(states) == st_crs(ak)
st_bbox(states) == nwa_bbox
tm_shape(states, bbox = nwa_bbox)+
tm_polygons(col = "#f2f2f2",
lwd = 0.2)+
tm_shape(ak)+
tm_borders(col = "#3399ff")+
tm_fill(col = "#86baff")+
tm_shape(wes)+
tm_borders(col = "#3399ff")+
tm_borders(col = "#86baff")+
tm_layout(
title = "Glaciers of Western North America",
title.position = c("center", "top"),
title.size = 1.1,
bg.color = "#fcfcfc",
inner.margins = c(0.06, 0.01, 0.09, 0.01),
outer.margins = 0,
frame.lwd = 0.2
)+
tm_compass(
type = "arrow",
position = c("right", "top"),
size = 1.2,
text.size = 0.6
)+
tm_scale_bar(
breaks = c(0, 1000, 2000),
position = c("right", "BOTTOM")
)
Load required libraries
library(sf)
library(dplyr)
library(purrr)
create a function that reads and cleans the data
prep <- function(dir) {
g <- st_read(dir)
g %<>% rename_with(~ tolower(gsub("Area....", "area", .x)))
g %<>% select(
year,
objectid,
glacname,
area,
shape_leng,
x_coord,
y_coord,
source_sca,
source
)
}
create a vector of dataset names
dirs <- grep("GNPglaciers_.*", list.dirs(), value = T)
pass each element of that vector through prep() thanks to map()
gnp <- map(dirs, prep)
st_crs(gnp[[1]]) == st_crs(gnp[[2]])
st_crs(gnp[[1]]) == st_crs(gnp[[3]])
st_crs(gnp[[1]]) == st_crs(gnp[[4]])