class: center, middle, inverse, title-slide # Working with Geospatial Data ## Projections ### Ben Baumer ### SDS 192April 10th, 2020(
http://beanumber.github.io/sds192/lectures/mdsr_geo_06-projections.html
) --- class: center, middle, inverse # Projections --- background-image: url(http://gisedu.colostate.edu/webcontent/nr505/2012_Projects/Team6/images/GIS_concepts/Figure2_proj.PNG) background-size: contain --- ## Principles .footnote[https://en.wikipedia.org/wiki/Map_projection] > "All projections of a sphere on a plane **necessarily distort** the surface in some way and to some extent." -- - Properties: - Area - Shape - Direction - Bearing - Distance -- - Every projection represents a trade-off in accuracy among these proporties --- ## Distortion .center[![](https://s-media-cache-ak0.pinimg.com/564x/ee/b8/ba/eeb8bafd454afce39587fdb960a55e85.jpg)] --- ## Projections .pull-left[ ![](https://media.giphy.com/media/wHASLyWK4zj5OhRCnv/giphy.gif) ] -- .pull-right[ - It's complicated (non-trivial math) - There is no one "best" projection - Explore: (https://bl.ocks.org/mbostock/raw/3711652/) ] -- .center[**Important!!: Not OK to pretend like projections don't matter**] --- ## [Mercator](https://en.wikipedia.org/wiki/Mercator_projection) (preserves angles) ![](https://upload.wikimedia.org/wikipedia/commons/f/f4/Mercator_projection_SW.jpg) --- ## [Gall-Peters](https://en.wikipedia.org/wiki/Gall–Peters_projection) (preserves area) .footnote[https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection#Controversy] ![](https://upload.wikimedia.org/wikipedia/commons/3/34/Gall%E2%80%93Peters_projection_SW.jpg) --- ## [Albers Equal Area](https://en.wikipedia.org/wiki/Albers_projection) ![](https://upload.wikimedia.org/wikipedia/commons/4/4f/Kavraiskiy_VII_projection_SW.jpg) --- ## [Lambert Conformal Conic](https://en.wikipedia.org/wiki/Lambert_conformal_conic_projection) ![](https://upload.wikimedia.org/wikipedia/commons/6/67/Lambert_cylindrical_equal-area_projection_SW.jpg) --- ## PROJ.4 strings and EPSG ```r library(sf) library(macleish) # GPS, Google Earth, Leaflet st_crs(4326) ``` ``` ## Coordinate Reference System: ## User input: EPSG:4326 ## wkt: ## GEOGCS["WGS 84", ## DATUM["WGS_1984", ## SPHEROID["WGS 84",6378137,298.257223563, ## AUTHORITY["EPSG","7030"]], ## AUTHORITY["EPSG","6326"]], ## PRIMEM["Greenwich",0, ## AUTHORITY["EPSG","8901"]], ## UNIT["degree",0.0174532925199433, ## AUTHORITY["EPSG","9122"]], ## AUTHORITY["EPSG","4326"]] ``` .footnote[https://epsg.io/4326] --- ## Checking projections ```r macleish_layers %>% pluck("buildings") %>% st_crs() ``` ``` ## Coordinate Reference System: ## User input: EPSG:4326 ## wkt: ## GEOGCS["WGS 84", ## DATUM["WGS_1984", ## SPHEROID["WGS 84",6378137,298.257223563, ## AUTHORITY["EPSG","7030"]], ## AUTHORITY["EPSG","6326"]], ## PRIMEM["Greenwich",0, ## AUTHORITY["EPSG","8901"]], ## UNIT["degree",0.0174532925199433, ## AUTHORITY["EPSG","9122"]], ## AUTHORITY["EPSG","4326"]] ``` --- ## Units really matter!! ```r macleish_layers %>% pluck("buildings") %>% st_bbox() ``` ``` ## xmin ymin xmax ymax ## -72.68251 42.44104 -72.67923 42.44919 ``` --- ## Projecting geospatial data ```r buildings_3857 <- macleish_layers %>% pluck("buildings") %>% * st_transform(3857) buildings_3857 %>% st_bbox() ``` ``` ## xmin ymin xmax ymax ## -8090979 5227276 -8090614 5228505 ``` --- ## Oops! ```r library(leaflet) leaflet() %>% addTiles() %>% # No error, but puts buildings at North Pole! addPolygons(data = buildings_3857, popup = ~name) ```
--- ## Projections checklist -
: Are you using `leaflet`? - Project everything in EPSG 4326 -- -
: Are you using `ggplot2`? - Choose a projection scheme that is appropriate for your data - Project everything in that scheme