<!-- class: inverse, center, title-slide, middle --> class: center, middle <style> .title-slide .remark-slide-number { display: none; } g { color: rgb(0,130,155) } r { color: rgb(174,77,41) } y { color: rgb(177,148,40) } </style> # Lecture 02: Geospatial Data Sciences # and Economic Spatial Models ## <img src="figs/bse_primary_logo.png" style="width: 35%" /><br><br>Bruno Conte ## 14-15/Jan/2025 --- # Geospatial Data and Spatial Models: Schedule 1. ~~Introduction to (spatial) data and programming in `R`~~ **[08/Jan/2025]** 2. Week 2-4: Vector spatial data **[14 - 29/Jan/2025]** - Week 2: Introduction and basics of vector data using `sf` - Week 3: Vector data operations: attribute- and spatial-based - Week 4: Geometry-based operations (or transformations) 3. Week 5-7: Raster spatial data + (basic) interactive tools **[05 - 19/Feb/2025]** 4. Week 8-10: Spatial models and applications with data **[25/Feb - 12 Mar/2025]**<br> <br> 5. <y>Take-home exam</y> **[26/Mar/2025]** --- # Main references for this class 1. Lovelace, R., Nowosad, J. and Muenchow, J., 2019. <g>**Geocomputation with R.**</g> Chapman and Hall/CRC. 2. Pebesma, E., 2018. Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10 (1), 439-446 3. Wickham, H. and Grolemund, G., 2016. R for data science: import, tidy, transform, visualize, and model data. " O'Reilly Media, Inc.". --- # Spatial data types: vector and raster - GIS systems represent spatial data in either <g>vector</g> or <g>raster</g> formats - **Vector data:** spatial geometries as a collection of points over a geography - Can represent <r>different objects</r> (points, lines, polygons, multiobjects) .center[ <img src="https://r.geocompx.org/figures/sfcs-1.png" style="width: 80%" /> ] --- # Spatial data types: vector and raster - GIS systems represent spatial data in either <g>vector</g> or <g>raster</g> formats - **Vector data:** spatial geometries as a collection of points over a geography - Can represent <r>different objects</r> (points, lines, polygons, multiobjects) .center[ <img src="https://r.geocompx.org/figures/multis-1.png" style="width: 80%" /> ] --- # Spatial data types: vector and raster - GIS systems represent spatial data in either <g>vector</g> or <g>raster</g> formats - **Raster data:** geography as continuos of pixels (gridcells) with associated values - Normally represents <r>high resolution</r> features of the geography (like an image) .center[ <img src="https://r.geocompx.org/figures/raster-intro-plot-1.png" style="width: 70%" /> ] --- # Spatial data types: vector and raster - Normally represents <r>high resolution</r> features of the geography (like an image) .center[ <img src="https://r.geocompx.org/figures/raster-intro-plot2-1.png" style="width: 70%" /> ] --- # Spatial data files: vector and raster - **Vector data:** file packages (usually multifiles) - Shapefiles (`*.shp`), contains also several auxiliar files (e.g. `*.dbf`, `*.shx`). <r>Most used!</r> - GeoJSON (`.json`) is written in Javascript (used mostly in web interfaces) - Geopackage (`*.gpk`), unique package/file - KMZ (`*.kmz`), from Google Earth format - **Raster data:** imagery - `*.tiff` (most used) - Other image files (e.g. `jpeg`, `gif`, `png`) - NetCDF files (`*.nc`) standardized data for geoscience (CDF = common data format) --- # Spatial data: sources There is almost **infinite** availability of spatial data in the internet. Here is a non-comprehensive list: .pull-left[ - <u>[Natural Earth:](https://www.naturalearthdata.com/downloads/)</u> immense GIS database - <u>[SAGE:](https://sedac.ciesin.columbia.edu/data/sets/browse)</u> also large GIS databse - <u>[DIVA:](https://www.diva-gis.org/gdata)</u> nice GIS database by country - <u>[GADM:](https://gadm.org/data.html)</u> country boundaries (ADM0-4) - <u>[USGS:](https://earthexplorer.usgs.gov/)</u> satellite imagery - <u>[Modis:](https://www.earthdata.nasa.gov/learn/find-data/near-real-time/rapid-response/modis-subsets)</u> satellite imagery - <u>[STRM:](https://dwtkns.com/srtm/)</u> elevation - <u>[SAGE:](https://sage.nelson.wisc.edu/data-and-models/datasets/)</u> land cover - <u>[GFC:](http://earthenginepartners.appspot.com/science-2013-global-forest/download_v1.1.html)</u> forest change - <u>[gROADS:](https://sedac.ciesin.columbia.edu/data/collection/groads)</u> road networks - <u>[Mineral Resources:](https://mrdata.usgs.gov/mrds/)</u> location of minerals ] .pull-right[ - <u>[AQUASTAT:](https://www.fao.org/aquastat/en/databases/)</u> water-related data - <u>[FAO-GAEZ:](https://gaez.fao.org/)</u> farm/land-related data - <u>[Harvest Choice:](https://www.ifpri.org/project/harvestchoice)</u> farm/land-related data - <u>[mapSPAM:](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/PRFF8V)</u> farm/land-related data - <u>[PS Lab:](https://psl.noaa.gov/data/gridded/index.html)</u> temperature/precipitation - <u>[SPEI:](https://spei.csic.es/database.html)</u> drought index - <u>[LSMS:](https://www.worldbank.org/en/programs/lsms)</u> geocoded surveys - <u>[DHS surveys:](https://dhsprogram.com/data/)</u> geocoded surveys - <u>[Geographic names:](https://geographic.org/geographic_names/index.html)</u> to geocode localities - <u>[Long-lat:](https://www.latlong.net/convert-address-to-lat-long.html)</u> API to geocode by names - <u>[NOAA VIIS:](https://www.ngdc.noaa.gov/eog/dmsp/downloadV4composites.html)</u> Satellite Nighttime lights ] --- class: inverse, center, middle # Getting started: Vector data # and the Simple Features in R --- # Vector data and geographical projections .pull-left[ - **Vector:** <g>collection of points</g> over a geography (longitude-latitude; i.e. X-Y) - X-Y geographical axis: change depending on the <r>geographical projection</r> - Same geometry can be represented by different combination of X-Y points - <g>Important takeaways:</g> 1. Know the data's projection system 2. Standardize them in you applications ] .pull-right[ <img src="https://pro.arcgis.com/en/pro-app/latest/help/mapping/properties/GUID-70E253E7-407E-469E-91DA-975B382EA6C9-web.png" style="width: 100%" /> ] --- # Vector data and geographical projections - **Most usual is WGS 84:** longitude (-180,180), latitude (-90,90); <g>CRS code EPSG:4326</g> - CRS = Coordinate Reference System (synonym to geographical projection) .center[ <img src="figs/grid_wgs_84.jpg" style="width: 70%" /> ] --- # Vector data in R: the simple features package .pull-left[ - Spatial data in R: a <r>Simple Feature</r><br>(the `sf` library) - State-of-art, standardized set of functions for GIS tasks - Replace "old" libraries (e.g. `sp`, `rgdal`) - <g>Revolution on GIS in R</g> (`#RSpatial`) - Interacts with `dplyr` "pipe" syntax - Computational- and memory-efficiency gains ] .pull-right[ .center[ Downloads of `R` libraries:<br> <img src="figs/cranlogs.png" style="width: 120%" /> ] ] --- # Vector data in R: the simple features package - **Core elements of a Simple Feature:** 1. <g>Geometry</g> (point, lines, polygons): a collection of points (`sfg`, simple feature geometry) 2. <r>Projection:</r> a CRS parameter that places the points over the world's geography (`sfc`, simple feature column) 3. <y>Attributes:</y> data associated with each feature/observation (1+2+3 = `sf`: simple feature) <br><br> .center[ <img src="figs/02-sfdiagram.png" style="width: 100%" /> ] --- # Vector data in R: the simple features package - Representation of a Simple Feature in `R` console .center[ <img src="figs/02-representation.png" style="width: 100%" /> ] --- # Vector data in R: creating simple features 1. Creating <g>geometries:</g> - Points: `st_point()` with a x-y **vector** - Lines: `st_linestring()` with a **matrix** of all x-y coordinates (columns) of each line vertex (rows) - Polygons: `st_polygon()` with a **list** containing a matrix of all x-y coordinates of each polygon vertex (first and last must be the same!) 2. Adding <r>projection:</r> `st_sfc(geometry,crs)` - Adds the `crs` projection to the `st_*()` geometry - WGS 84: use `crs = 'EPSG:4326'` 3. Creating a <y>simple feature:</y> `st_sf(data.attributes,geometry = sfc)` --- class: inverse, center, middle # Vector data with Simple Features: # attribute data operations --- # Vector data operations - **Operations of spatial features** (i.e. manipulation): by attribute or geometry (spatial) - <g>Attribute</g> opperations: disciplined by the underlying attributes (feature's dataset) - <g>Spatial</g> operations: manipulations across the space (i.e. rotating, moving, distances, etc.) - Attribute data operations: - Nested on `dplyr` "pipe" operators/funtions (e.g. filter, slice, etc.) - Equivalent to data operations but also <r>accounting for the geometry</r> of the feature - **Detailed exposition:** on class material `01_class02.R` --- # Hands-on: your turn! (1/2) .pull-left[ - Creating <g>artificial spatial data</g> with `sf` - Generate the following features: - `MULTIPOINT ((3.2 4), (3 4.6), (3.8 4.4), (3.5 3.8), (3.4 3.6), (3.9 4.5))` - `LINESTRING (0 3, 0 4, 1 5, 2 5)` - `POLYGON ((0 0, 1 0, 3 2, 2 4, 1 4, 0 0))` - <r>Plot them</r> together with `ggplot()` ] .pull-right[ <!-- --> ] --- # Hands-on: your turn! (2/2) - **Map of world airports:** download the shapefile of <r>airports</r> in the world from Natural Earth (large scale data). Differentiate airport <g>types by color</g> .center[ <img src="figs/map_airports.png" style="width: 100%" /> ]