SPATIAL MAPS CONT.
STA465: Theory and Methods for Complex Spatial Data
Instructor: Dr. Vianey Leos Barajas
QUICKLY BACK TO MAP PROJECTIONS
We saw that there are ways to ‘map’ the Earth in 2D
We can only preserve one to two elements (), so we always introduce biases of some sort into the maps we make.
➤ ➤
A BIG PART OF BEING A STATISTICIAN: IDENTIFYING BIASES
‘The True Size Of…”
In mathematical statistics, you learn about biases of estimators, asymptotic behaviour, etc.
From a non-mathematical perspective, individuals introduce biases into an analysis by the choices they make:
The models they choose
The visualizations that are made — like maps! How results are presented
➤
➤
➤
➤ ➤ ➤
MANIPULATING SPATIAL DATA STRUCTURES
COMBINING DATA WITH DIFFERENT CRS/STRUCTURE — OAHU, HI, USA
Hawaii Soil Atlas: https://gis.ctahr.hawaii.edu/SoilAtlas
SOIL FERTILITY CLASS DATA SET
What kind of file is it? Simple feature or raster? CRS?
Geometry type?
➤ ➤ ➤ ➤
WHAT IT LOOKS LIKE IN R
MAPPING SOIL FERTILITY CLASS ACROSS OAHU
USA ELEVATION
usa_elev <- raster::getData('alt', country='USA', level=1)
MAPPING ELEVATIONS ACROSS HAWAII
WHAT I NEEDED FOR MY WORK
At specific points across, Oahu, I wanted to identify soil fertility class, elevation, etc.
How do you put it all together?
It takes a few steps that, for me, were not very intuitive!
➤
➤
➤
TO START, WHAT POINTS DO I NEED INFORMATION FOR?
I first started out with coordinates that I extracted from the USA elevation source:
rasterToPoints(usa_elev[[4]])
This is a matrix, with two columns x and y for longitude and latitude — not a spatial object, yet.
➤
➤
➤
THEN WHAT?
dsp <- sf::st_as_sf(data.frame(oahu), coords=c("x", "y"), crs=4326)
dsp <- sf::st_transform(dsp, crs=st_crs(fertility))
oahufertility <- sf::st_join(x = dsp, y=fertility[dsp,c("FertClass")], join=st_intersects) [1+2*(0:1912),]
st_transform(); st_as_sf(); st_intersects()
➤
➤ ➤
➤
FINAL DATA SET
TO MAKE THE MAP OF FERTILITY CLASS:
tm_shape(fertility[oahufertility,]) +
tm_fill("FertClass", pal="-viridis", title="Fertility Class")
CLIPPING, CROPPING AND MORE
WHAT DOES THE DATA LOOK LIKE WHEN COMBINED?
CLIPPING AND CROPPING (+ MASKING)
Spatial clipping: spatial subsetting that changes the geometry columns of at least some of the affected features
Raster cropping + masking:
Often a raster may be bigger than the area of study, cropping is one way to reduce the dimension.
Masking sets values outside of a boundary to “NA”
➤
➤
➤
➤
CLIPPING TYPES
CLIPPING EXAMPLE
CROPPING
CROPPING
GEOMETRY UNIONS: US_STATES DATA SET — SPDATA R PACKAGE
GEOMETRY UNIONS
RASTERIZATION AND VECTORIZATION
Sometimes you will want/need to switch between rasters and vector objects
In R, it’s possible to change between types to suit your needs
Rasterization: conversion of vector objects into their representation in raster objects
Vectorization: converts spatially continuous raster data into spatially discrete data such as points, lines or polygons
➤
➤
➤
➤
RASTERIZATION: 5.4.3 IN GEOCOMPUTATION WITH R
In the ‘raster’ R package, we have the function: ‘rasterize()’
➤
IN THE PREVIOUS EXAMPLE, TO RASTERIZE....
There were a few steps to making a raster.
First, we need to make a ‘raster template’ - it contains no values
➤
➤
➤
Then, we can combine the points and raster template to create the new rasterized objects!
RASTERIZATION: 5.4.3 IN GEOCOMPUTATION WITH R
VECTORIZATION (OF RASTER OBJECTS)
VECTORIZATION — TO POLYGONS!
RASTER TO....POINTS, POLYGONS, AND CONTOURS
In the `raster’ R package, there exist a few more options:
➤
➤ ➤ ➤
rasterToPoints() rasterToPolygons() rasterToContour()
MAPS + INTERACTIVE VISUALIZATIONS UP NEXT
INTERACTIVE MAPS
There are lots of ways to make maps interactive in R
Interactivity allows for greater exploration of the data
We can work with different R packages to make maps interactive in different ways:
Shiny leaflet tmap mapview
➤
➤
➤
➤ ➤ ➤ ➤