class: center, middle, inverse, title-slide # Tutorial: Geocomputation with R ## ⚔
The basics ### Jannes Muenchow, Robin Lovelace ### ERUM Budapest, 2018-05-14 --- layout: true background-image: url(img/r_geocomp_background.png) background-size: cover --- # Find the slides and code <br> <br> <br> <br> https://github.com/jannes-m/erum18_geocompr <br> <br> Please install following packages: ```r install.packages(c("sf", "raster", "spData", "dplyr", "RQGIS")) ``` Or from [docker](https://github.com/Robinlovelace/geocompr#running-the-book-in-docker): ``` docker run -d -p 8787:8787 -v ${pwd}:/data robinlovelace/geocompr ``` --- layout: false # Contents of the tutorial <figure> <img align="right" src="img/globe.png" width = "60%", height = "60%"/> </figure> 1. Basics -- 1. Spatial vector data -- 1. Spatial raster data -- 1. Mapping -- 1. Bridges to GIS -- 1. (Spatial statistical learning) --- # Who are we <figure> <img align="right" src="img/globe.png" width = "60%", height = "60%"/> </figure> - [Jannes Muenchow](http://www.geographie.uni-jena.de/en/Muenchow.html) - GIScientist from Jena with a special focus on ecology, landsliding and geomarketing; creator of the **RQGIS** package -- - [Robin Lovelace](https://www.robinlovelace.net/) - Geographer and Environmental Scientist focussing on sustainable transport planning; creator of **stplanr** -- - together with [Jakub Nowosad](https://nowosad.github.io/) we are writing: <br> <br> <center> <b> <font size = "6"> [Geocomputation with R](https://geocompr.robinlovelace.net/) --- layout: true background-image: url(img/r_geocomp_background.png) background-size: cover --- # Where are we from <center>
--- class: inverse, center, middle # Some definitions --- # What is a GIS? <figure> <img align="right" src="img/gis_logos.png" width = "40%", height = "40%"/> </figure> - A **G**eographic **I**nformation **S**ystem is a system for the analysis, manipulation and visualization of geographical data (Longley, Goodchild, Maguire, and Rhind, 2015). -- - Six components of a GIS: software, data, procedures, hardware, people, network -- - Typical GIS software packages: QGIS, SAGA-GIS, GRASS-GIS, ArcMap (commercial) ??? Remember R has never been intended to be a GIS though it is great that we can use it as one. Certain spatial operations are not possible. But R has been designed from the beginning as an interface to other languages. And later on, we will see how we can build bridges from R to GIS software. --- # What is geocomputation? - Geocomputation - GIScience - Geographic data science -- ### Graphical User Interface (GUI) GIS vs Geocomputation with R <table> <thead> <tr> <th style="text-align:left;"> Attribute </th> <th style="text-align:left;"> Desktop GIS (GUI) </th> <th style="text-align:left;"> R </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Home disciplines </td> <td style="text-align:left;"> Geography </td> <td style="text-align:left;"> Computing, Statistics </td> </tr> <tr> <td style="text-align:left;"> Software focus </td> <td style="text-align:left;"> Graphical User Interface </td> <td style="text-align:left;"> Command line </td> </tr> <tr> <td style="text-align:left;"> Reproducibility </td> <td style="text-align:left;"> Minimal </td> <td style="text-align:left;"> Maximal </td> </tr> </tbody> </table> <br> <br> -- Further reading: [https://geocompr.robinlovelace.net/intro.html#what-is-geocomputation](https://geocompr.robinlovelace.net/intro.html#what-is-geocomputation) ??? "Geographic information systems are useful tools, helping everyone from scientists to citizens to solve geographic problems. But like many other kinds of tools, such as computers themselves, their use raises questions that are sometimes frustrating, and sometimes profound. For example, how does a GIS user know that the results obtained are accurate? What principles might help a GIS user to design better maps? How can locationbased services be used to help users to navigate and understand human and natural environments? Some of these are questions of GIS design, and others are aboutGIS data and methods. Taken together, we can think of them as questions that arise from the use of GIS - that are stimulated by exposure to GIS or to its products. Many of them are addressed in detail at many points in this book, and the book's title emphasizes the importance of both systems and science. The term geographic information science was coined in a paper by Michael Goodchild published in 1992. In it, the author argued that these questions and others like them were important, and that their systematic study constituted a science in its own right. Information science studies the fundamental issues arising from the creation, handling, storage, and use of information - similarly, GIScience should study the fundamental issues arising from geographic information, as a well-defined class of information in general. Other terms have much the same meaning: geomatics and geoinformatics, spatial information science, geoinformation engineering. All suggest a scientific approach to the fundamental issues raised by the use of GIS and related technologies, though they all have different roots and emphasize different ways of thinking about problems (specifically geographic or more generally spatial, emphasizing engineering or science, etc.) (Longley et al., 2005)." "There are many close synonyms for geographic information science (GIScience), one of which is geocomputation - a term first coined by the geographer Stan Openshaw to describe the scientific application of computationally-intensive techniques to problems with a spatial dimension" (Longley et al., 2005). --- class: inverse, center, middle # Geographic data models --- # Geographic data - Geographic data consists of **xy-coordinates** and corresponding **attributes** (this might include a time stamp, otherwise the data is static). -- - Usually we neglect the curvature of the Earth when visualizing geographic data. -- - Geographic data only represents a simplified representation of the world. So we decide what we display for which purpose. -- - Geographic data can quickly become big. -- - Two data models for representing digitally geographic data: **the vector** and **the raster** data model ??? Do not confuse the spatial vector data model with the vectors in R. The two are completely different things and in fact unrelated. Though we will see that we use vectors in R to represent the spatial vector data model. --- # Vector data model <figure> <img align="right" src="img/vector.png" width = "60%", height = "60%"/> </figure> - Discrete objects represented by points -- - Three main subtypes: points, lines and polygons -- - Especially suitable for objects with well-defined borders (lakes, houses, streets, etc.) -- - Attribute table <br> <br> <br> <br> <br> <br> Further reading: [https://geocompr.robinlovelace.net/spatial-class.html#vector-data](https://geocompr.robinlovelace.net/spatial-class.html#vector-data) --- # Raster data model <figure> <img align="right" src="img/raster.png" width = "50%", height = "50%"/> </figure> - Continous fields represented by pixels (cells) -- - One attribute value for one cell -- - Especially suitable for continous data without sharp borders (elevation, precipitation) -- - Structure: raster header (origin, resolution, ncol, nrow, crs, NAvalue) and matrix containing the data -- - Map algebra -- <br> <br> <br> <br> <br> <br> <br> Further reading: [https://geocompr.robinlovelace.net/spatial-class.html#raster-data](https://geocompr.robinlovelace.net/spatial-class.html#raster-data) --- # Raster header <center> <figure> <img src="img/raster_header.png" width = "100%", height = "100%"/> </figure> --- class: inverse, center, middle # A brief word on CRS --- # A brief word on CRS We use Coordinate Reference Systems (CRS) to locate our geographic data on Earth. We distinguish between: - Geographical CRS span the entire world - Projected CRS are (usually) localized to minimize visual distortion in a particular region (use a specific ellipsoid which is especially suitable for a this particular part of the Earth) ??? CRS consists of a reference ellipsoid, a datum (defines the origin. I think of this as the base information needed to “draw” the imaginary coordinate lines on a globe or map. A datum is chosen to give the best possible fit to the true shape of the Earth. ) A geographic CRS uses a grid that wraps around the entire globe. This means that each point on the globe is defined using the SAME coordinate system and the same units as defined within that particular geographic CRS. --- # Geographic CRS .pull-left[ - Usually in decimal degrees - Used by many people/institutions (GPS) - Great for locating a place on Earth - Best for global analysis - Less suitable if you want to measure distance ] .pull-right[ <img src="https://geocompr.robinlovelace.net/figures/vector_lonlat.png" width = "90%", height = "90%"/> <figcaption >Source: <a href="https://geocompr.robinlovelace.net/spatial-class.html">Geocomputation with R</a>.</figcaption> </figure> ] ??? difference 1 decimal degree at the equator and at the poles --- # Geographic CRS .pull-left[ - Usually in decimal degrees - Used by many people/institutions (GPS) - Great for locating a place on Earth - Best for global analysis - Less suitable if you want to measure distance - Heavily distorted towards the poles ] .pull-right[ ![](01_basics_files/figure-html/unnamed-chunk-6-1.png)<!-- --> ] ??? difference 1 decimal degree at the equator and at the poles --- # Projected CRS - Spatial projections flatten the 3D shape of the Earth onto a 2D plane - Especially suitable for "local" analysis .pull-right[ <figure> <img src="img/spatial-projection-transformations-crs.png" width = "90%", height = "90%"/> <figcaption>Source: <a href="http://progonos.com/furuti/">progonos.com/furuti/</a> </figcaption> </figure> ] -- <br> Further reading: - [Gecomputation with R - Projections](https://geocompr.robinlovelace.net/transform.html#reproj-geo-data) - [QGIS CRS documentation](https://docs.qgis.org/2.14/en/docs/gentle_gis_introduction/coordinate_reference_systems.html) - [Earth Data Science CRS](https://earthdatascience.org/courses/earth-analytics/spatial-data-r/intro-to-coordinate-reference-systems/) ??? conic, azimuthal and cylindrical projections --- class: inverse, center, middle # Brief history of R-spatial --- # Brief history of R-spatial - Spatial packages already available in the S language since the 1990s (Bivand and Gebhardt, 2000) -- - By 2000, modifications of these became R packages for point pattern analysis, geostatistics, exploratory spatial data analysis and spatial econometrics -- - R-GIS bridges (Bivand, 2000) -- - Bivand (2003) proposed a spatial data class system for R which eventually led to the packages **rgdal** (first released in 2003; Bivand, Keitt, and Rowlingson, 2018) and **sp** (first released in 2005; Bivand, Pebesma, and Gomez-Rubio, 2013) -- - 2008: Applied Spatial Data Analysis with R (Bivand, Pebesma, and Gomez-Rubio, 2013) -- - 2010: **raster** package (Hijmans, 2017) -- - 2011: **rgeos** package (Bivand and Rundel, 2017) -- - 2016-17: **sf** - simple features for R (Pebesma, 2018a) -- - 2017-18: **stars** - spatiotemporal tidy arrays for R (Pebesma, 2018b) -- <br> <br> <br> Further reading: [https://geocompr.robinlovelace.net/intro.html#the-history-of-r-spatial](https://geocompr.robinlovelace.net/intro.html#the-history-of-r-spatial) --- layout: false # Recap <figure> <img align="right" src="img/globe.png" width = "60%", height = "60%"/> </figure> - What is a GIS? -- - What is Gecomputation? -- - Why is geographic data special? -- - Difference between the spatial vector and raster data model -- - CRS -- - Brief history of R-spatial --- class: small # References Bivand, Roger (2003). "Approaches to Classes for Spatial Data in R". In: _Proceedings of DSC_. Ed. by Kurt Hornik, Friedrich Leisch and Achim Zeileis. URL: [https://www.r-project.org/nosvn/conferences/DSC-2003/Proceedings/Bivand.pdf](https://www.r-project.org/nosvn/conferences/DSC-2003/Proceedings/Bivand.pdf) (visited on Jun. 27, 2017). Bivand, Roger S. (2000). "Using the R Statistical Data Analysis Language on GRASS 5.0 GIS Database Files". In: _Computers & Geosciences_ 26.9, pp. 1043-1052. URL: [http://www.sciencedirect.com/science/article/pii/S0098300400000571](http://www.sciencedirect.com/science/article/pii/S0098300400000571) (visited on Jul. 11, 2017). Bivand, Roger S, Edzer Pebesma and Virgilio Gomez-Rubio (2013). _Applied Spatial Data Analysis with R_. 2nd ed.. New York: Springer. 405 pp. ISBN: 978-1-4614-7617-7. Bivand, Roger and Albrecht Gebhardt (2000). "Implementing Functions for Spatial Statistical Analysis Using the Language". In: _Journal of Geographical Systems_ 2.3, pp. 307-317. URL: [http://www.springerlink.com/index/CJRPUMB78JUYH54W.pdf](http://www.springerlink.com/index/CJRPUMB78JUYH54W.pdf) (visited on Jul. 12, 2017). Bivand, Roger, Tim Keitt and Barry Rowlingson (2018). _Rgdal: Bindings for the 'Geospatial' Data Abstraction Library_. R package version 1.2-18. URL: [https://CRAN.R-project.org/package=rgdal](https://CRAN.R-project.org/package=rgdal). Bivand, Roger and Colin Rundel (2017). _Rgeos: Interface to Geometry Engine - Open Source ('GEOS')_. R package version 0.3-26. URL: [https://CRAN.R-project.org/package=rgeos](https://CRAN.R-project.org/package=rgeos). Hijmans, Robert J. (2017). _Raster: Geographic Data Analysis and Modeling_. R package version 2.6-7. URL: [https://CRAN.R-project.org/package=raster](https://CRAN.R-project.org/package=raster). Longley, Paul, Michael Goodchild, David Maguire, et al. (2015). _Geographic Information Science & Systems_. Fourth edition. Hoboken, NJ: Wiley. 477 pp. ISBN: 978-1-118-67695-0. Pebesma, Edzer (2018a). _Sf: Simple Features for R_. R package version 0.6-2. URL: [https://CRAN.R-project.org/package=sf](https://CRAN.R-project.org/package=sf). Pebesma, Edzer (2018b). _Stars: Scalable, Spatiotemporal Tidy Arrays for R_. R package version 0.1-1. URL: [https://github.com/r-spatial/stars/](https://github.com/r-spatial/stars/).