the raster package
play

The raster package Working with Geospatial Data in R Data frames - PowerPoint PPT Presentation

Working with Geospatial Data in R The raster package Working with Geospatial Data in R Data frames arent a great way to store spatial data > head(preds) lon lat predicted_price 1 -123.3168 44.52539 258936.2 2 -123.3168


  1. Working with Geospatial Data in R The raster package

  2. Working with Geospatial Data in R Data frames aren’t a great way to store spatial data > head(preds) lon lat predicted_price 1 -123.3168 44.52539 258936.2 2 -123.3168 44.52740 257258.4 3 -123.3168 44.52940 255543.1 4 -123.3168 44.53141 253791.0 5 -123.3168 44.53342 252002.4 6 -123.3168 44.53542 250178.7 ● No CRS information ● Ine ffi cient storage ● Ine ffi cient display

  3. Working with Geospatial Data in R A be � er structure for raster data ● data matrix + information on grid + CRS 258936.2 256579.2 254147.2 251593.8 … 258936.2 256579.2 254147.2 251593.8 … 257258.4 255082.5 252848.8 250499.2 258936.2 256579.2 254147.2 251593.8 … 257258.4 255082.5 252848.8 250499.2 255543.1 253557.9 251537.5 249410.6 257258.4 255082.5 252848.8 250499.2 255543.1 253557.9 251537.5 249410.6 253791.0 252004.4 250211.4 248326.8 255543.1 253557.9 251537.5 249410.6 253791.0 252004.4 250211.4 248326.8 … 253791.0 252004.4 250211.4 248326.8 … …

  4. Working with Geospatial Data in R The raster package ● sp provides some raster data classes: ● SpatialGrid, SpatialPixels, SpatialGridDataFrame, SpatialPixelsDataFrame ● But raster is be � er: ● easier import of rasters ● large rasters aren’t read into memory ● provides functions for raster type operations ● Also uses S4 and when appropriate provides same functions

  5. Working with Geospatial Data in R raster provides print methods for sp objects > library(sp) > countries_spdf An object of class "SpatialPolygonsDataFrame" Slot "data": name iso_a3 population gdp region 1 Afghanistan AFG 28400000 22270.00 2 Angola AGO 12799293 110300.00 3 Albania ALB 3639453 21810.00 … VERY long output! Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

  6. Working with Geospatial Data in R raster provides print methods for sp objects > library(raster) > countries_spdf class : SpatialPolygonsDataFrame features : 177 extent : -180, 180, -90, 83.64513 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 … variables : 6 names : name, iso_a3, population, gdp, min values : Afghanistan, -99, 140, 16.00, max values : Zimbabwe, ZWE, 1338612970, 15094000.00, … Compact and useful output

  7. Working with Geospatial Data in R Let’s practice!

  8. Working with Geospatial Data in R Color

  9. Working with Geospatial Data in R A perceptual color space: HCL ● Trichromatic - we perceive color as three-dimensional h hue unordered (circular) c < < ? ? ? chroma ordered l luminance ordered Image credit: Hadley Wickham

  10. Working with Geospatial Data in R Types of scale ● Sequential - ordered steps in chroma and/or luminance hue maybe redundant coding ● Diverging - ordered but in two directions steps in chroma and/or luminance with hue distinguishing direction ● Qualitative - unordered steps in hue with equal chroma and luminance

  11. Working with Geospatial Data in R Generating color scales in R > library(RColorBrewer) > display.brewer.all() > brewer.pal(n = 9, "Blues") [1] "#F7FBFF" "#DEEBF7" "#C6DBEF" "#9ECAE1" [5] "#6BAED6" "#4292C6" "#2171B5" "#08519C" [9] "#08306B" > library(viridisLite) > viridis(n = 9) transparency [1] "#440154FF" "#472D7BFF" "#3B528BFF" "#2C728EFF" [5] "#21908CFF" "#27AD81FF" "#5DC863FF" "#AADC32FF" [9] "#FDE725FF"

  12. Working with Geospatial Data in R Let’s practice!

  13. Working with Geospatial Data in R Color scales 2

  14. Working with Geospatial Data in R Mapping of numbers to color ● ggplot2 : map to a continuous gradient of color 250000 ● tmap : map to a discrete set of colors ● Continuous map: control mapping by transforming the scale, e.g log ● Discrete map: control mapping by binning 0.5 the variable

  15. Working with Geospatial Data in R Discrete vs. continuous mapping ● Continuous: ● Perceptually uniform: perceiving equivalent color di ff erence to numerical di ff erence ● Discrete: ● Complete control over scale ● Easier lookup

  16. Working with Geospatial Data in R Cu � ing a variable into bins > library(classInt) > classIntervals(values, n = 5, style = "equal") style: equal [190135.1,208293.7) [208293.7,226452.4) [226452.4,244611.1) 537 528 351 [244611.1,262769.7) [262769.7,280928.4] 131 53 > classIntervals(values, n = 5, style = "quantile") style: quantile [190135.1,201403.2) [201403.2,211412.2) [211412.2,220703.1) 320 320 320 [220703.1,237403.2) [237403.2,280928.4] 320 320

  17. Working with Geospatial Data in R Cu � ing a variable into bins > classIntervals(values, n = 5, style = "pretty") style: pretty [180000,2e+05) [2e+05,220000) [220000,240000) [240000,260000) 279 664 394 199 [260000,280000) [280000,3e+05] 62 2 > classIntervals(values, style = "fixed", fixedBreaks = c(100000, 230000, 255000, 300000)) style: fixed [1e+05,230000) [230000,255000) [255000,3e+05] 1120 390 90

  18. Working with Geospatial Data in R Let’s practice!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend