Chapter 7

Harold Nelson

11/8/2021

library(raster)         
## Loading required package: sp
library(rgdal)          
## Please note that rgdal will be retired by the end of 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## 
## rgdal: version: 1.5-27, (SVN revision 1148)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
## Overwritten PROJ_LIB was /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj
library(RColorBrewer) 
library(rasterVis)    
## Loading required package: lattice
library(ggplot2)      
library(colorspace)
## 
## Attaching package: 'colorspace'
## The following object is masked from 'package:raster':
## 
##     RGB
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:raster':
## 
##     extract
library(readr)
library(sf)
## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
library(tmap)
## Registered S3 methods overwritten by 'stars':
##   method             from
##   st_bbox.SpatRaster sf  
##   st_crs.SpatRaster  sf
nlcd16 <- raster("NLCD_2016_Land_Cover_WaltonGA.tiff")
is.na(nlcd16) = 0
tm_shape(nlcd16) + tm_raster(style = "cat") 
## stars object downsampled to 1067 by 937 cells. See tm_shape manual (argument raster.downsample)

nlcd16[nlcd16 < 20] = 1
nlcd16[nlcd16 > 1 & nlcd16 < 30] = 2
nlcd16[nlcd16 > 2 & nlcd16 < 40] = 3
nlcd16[nlcd16 > 3 & nlcd16 >= 40 ] = 4


tm_shape(nlcd16) + tm_raster(style = "cat",
                             palette = c("blue","orange","grey","green"), 
                             labels = c("Wet","Developed","Barren","Green")) +
  tm_layout(legend.outside = T)
## stars object downsampled to 1067 by 937 cells. See tm_shape manual (argument raster.downsample)