class: center, middle, inverse, title-slide # Working with Geospatial Data ## MacLeish ### Ben Baumer ### SDS 192April 6th, 2020(
http://beanumber.github.io/sds192/lectures/mdsr_geo_02-macleish.html
) --- class: center, middle, inverse # `macleish` --- ## The `macleish` package .pull-left[ - Weather data - Whately (Jan 2012 -now) - Orchard (June 2014 - now) - temperature, wind speed, humidity, pressure, rainfall, etc. ] .pull-right[ - Spatial data - Buildings - Streams - Forests - Slopes - etc. ] - Get the CRAN version ```r install.packages("macleish") ``` -- - Get the latest version ```r devtools::install_github("beaumber/macleish") ``` --- ## Layers ```r library(macleish) names(macleish_layers) ``` ``` ## [1] "landmarks" "forests" "streams" ## [4] "challenge_courses" "buildings" "wetlands" ## [7] "boundary" "research" "soil" ## [10] "trails" "contours_30ft" "contours_3m" ``` ```r macleish_layers[["trails"]] ``` ``` ## Simple feature collection with 15 features and 2 fields ## geometry type: LINESTRING ## dimension: XY ## bbox: xmin: -72.68513 ymin: 42.44177 xmax: -72.67731 ymax: 42.4618 ## CRS: EPSG:4326 ## First 10 features: ## name color geometry ## 1 Porcupine Trail White LINESTRING (-72.68291 42.45... ## 2 Western Loop Red LINESTRING (-72.68111 42.45... ## 3 Poplar Hill Road Road LINESTRING (-72.68155 42.45... ## 4 Vernal Pool Loop Yellow LINESTRING (-72.68265 42.44... ## 5 Eastern Loop Blue LINESTRING (-72.68113 42.45... ## 6 Western Loop Red LINESTRING (-72.68401 42.45... ## 7 Western Loop Red LINESTRING (-72.68088 42.44... ## 8 entry trail - LINESTRING (-72.68088 42.44... ## 9 Eastern Loop Blue LINESTRING (-72.68063 42.45... ## 10 Easy Out Red LINESTRING (-72.67962 42.45... ``` --- ## Accessing items in a `data.frame` ```r names(mtcars) ``` ``` ## [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" ## [11] "carb" ``` ```r # vector within a data.frame mtcars$mpg ``` ``` ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 ## [31] 15.0 21.4 ``` ```r # same, tidyverse way mtcars %>% * pull(mpg) ``` ``` ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 ## [31] 15.0 21.4 ``` --- ## Accessing items in a `data.frame` ```r class(mtcars["mpg"]) ``` ``` ## [1] "data.frame" ``` -- ```r class(mtcars[["mpg"]]) ``` ``` ## [1] "numeric" ``` ```r class(mtcars$mpg) ``` ``` ## [1] "numeric" ``` ```r class(pull(mtcars, mpg)) ``` ``` ## [1] "numeric" ``` --- ## Accessing items in a `list` ```r library(macleish) class(macleish_layers) ``` ``` ## [1] "list" ``` ```r class(macleish_layers["buildings"]) # returns list ``` ``` ## [1] "list" ``` ```r class(macleish_layers[["buildings"]]) # returns sf ``` ``` ## [1] "sf" "data.frame" ``` ```r # tidyverse way macleish_layers %>% pluck("buildings") %>% class() ``` ``` ## [1] "sf" "data.frame" ``` --- ## Selectors - give me the same kind of thing - `[` - extract the thing and give it to me - base R: `$`, `[[` - `tidyverse`: - from a `data.frame`: `pull()` - from a `list`: `pluck()` --- ## Tidy pipelines ```r macleish_layers %>% pluck("trails") ``` ``` ## Simple feature collection with 15 features and 2 fields ## geometry type: LINESTRING ## dimension: XY ## bbox: xmin: -72.68513 ymin: 42.44177 xmax: -72.67731 ymax: 42.4618 ## CRS: EPSG:4326 ## First 10 features: ## name color geometry ## 1 Porcupine Trail White LINESTRING (-72.68291 42.45... ## 2 Western Loop Red LINESTRING (-72.68111 42.45... ## 3 Poplar Hill Road Road LINESTRING (-72.68155 42.45... ## 4 Vernal Pool Loop Yellow LINESTRING (-72.68265 42.44... ## 5 Eastern Loop Blue LINESTRING (-72.68113 42.45... ## 6 Western Loop Red LINESTRING (-72.68401 42.45... ## 7 Western Loop Red LINESTRING (-72.68088 42.44... ## 8 entry trail - LINESTRING (-72.68088 42.44... ## 9 Eastern Loop Blue LINESTRING (-72.68063 42.45... ## 10 Easy Out Red LINESTRING (-72.67962 42.45... ```