Welcome!: Zev Ross
Welcome!: Zev Ross
Welcome!
Zev Ross
President,
ZevRoss Spatial Analysis
DataCamp Spatial Analysis with sf and raster in R
sf for vectors
raster for grids
ggplot2
tmap
dplyr
DataCamp Spatial Analysis with sf and raster in R
You will compute tree density and greenspace by neighborhood in New York City.
DataCamp Spatial Analysis with sf and raster in R
Read in raster data using the raster package and either the raster() or
brick() functions
DataCamp Spatial Analysis with sf and raster in R
An st_read() example
> library(sf)
> county <- st_read("folder1/county.shp")
DataCamp Spatial Analysis with sf and raster in R
Single-band rasters
These have a single band/layer with a set of values, so one value per grid cell
Examples might include rasters of elevation or land use
DataCamp Spatial Analysis with sf and raster in R
Multi-band rasters
Each grid cell has multiple values, one for each layer
Examples include satellite images or aerial photos
DataCamp Spatial Analysis with sf and raster in R
Let's practice!
DataCamp Spatial Analysis with sf and raster in R
Zev Ross
President,
ZevRoss Spatial Analysis
DataCamp Spatial Analysis with sf and raster in R
A non-spatial example
> new_list
[[1]]
[1] 1 2
[[2]]
[1] 1 2 3 4 5
[[3]]
[1] 1 2 3
DataCamp Spatial Analysis with sf and raster in R
Each list element can contain as much (or as little) detail as you need.
library(dplyr)
> d <- tbl_df(d)
> d
# A tibble: 3 x 3
a b c
<int> <int> <list>
1 1 1 <int [2]>
2 2 2 <int [5]>
3 3 3 <int [3]>
DataCamp Spatial Analysis with sf and raster in R
> head(trees, 3)
# Simple feature collection with 6 features and 2 fields
# geometry type: POINT
# dimension: XY
# bbox: xmin: -74.13116 ymin: 40.62351 xmax: -73.80057 ...
# epsg (SRID): 4326
# proj4string: +proj=longlat +datum=WGS84 +no_defs
# tree_id species geometry
# 1 558423 honeylocust POINT(-73.8005714931568 40....
# 2 286191 Callery pear POINT(-73.9542172518889 40....
# 3 257044 Chinese elm POINT(-73.9230947243388 40....
DataCamp Spatial Analysis with sf and raster in R
> is.list(trees$species)
[1] FALSE
> is.list(trees$geometry)
[1] TRUE
> class(trees$geometry)
[1] "sfc_POINT" "sfc"
DataCamp Spatial Analysis with sf and raster in R
Let's practice!
DataCamp Spatial Analysis with sf and raster in R
Zev Ross
President,
ZevRoss Spatial Analysis
DataCamp Spatial Analysis with sf and raster in R
Note that under "names" there is just one name, meaning just one band/layer.
DataCamp Spatial Analysis with sf and raster in R
Notice that instead of one name there are three, meaning that this is a multi-band
raster.
DataCamp Spatial Analysis with sf and raster in R
extent() gives the minimum and maximum X and Y coordinates of the raster
> extent(multiband)
# class : Extent
# xmin : 575667.9
# xmax : 599689.7
# ymin : 4503277
# ymax : 4526468
DataCamp Spatial Analysis with sf and raster in R
ncell() and nlayers() give the total number of grid cells or layers, respectively
> ncell(multiband)
[1] 619173
> nlayers(multiband)
[1] 3
DataCamp Spatial Analysis with sf and raster in R
> crs(multiband)
# CRS arguments:
# +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs +ellps=WGS84 ...
DataCamp Spatial Analysis with sf and raster in R
The inMemory() function tells you if the raster values have been
read into R
> inMemory(multiband)
[1] FALSE
DataCamp Spatial Analysis with sf and raster in R
band raster
Use plotRGB() to create a true color map of a multi-layered object
DataCamp Spatial Analysis with sf and raster in R
Let's practice!