Attribute | Desktop GIS (GUI) | R |
---|---|---|
Home disciplines | Geography | Computing, Statistics |
Software focus | Graphical User Interface | Command line |
Reproducibility | Minimal | Maximal |
Jakub Nowosad, https://jakubnowosad.com/
OpenGeoHub Summer School 2022
2022-08-30
(geo)spati|graphic)*(al)*
( )*(stuff|data|comput|inform)*(ing|ation)*
(science|systems|theory|analysis)*
(geo)spati|graphic)*(al)*
( )*(stuff|data|comput|inform)*(ing|ation)*
(science|systems|theory|analysis)*
GeoComputation is about using the various different types of geodata and about developing relevant geo-tools within the overall context of a ‘scientific’ approach (Openshaw 2000).
At the turn of the 21st Century it was unrealistic to expect readers to be able to reproduce code examples, due to barriers preventing access to the necessary hardware, software and data
Attribute | Desktop GIS (GUI) | R |
---|---|---|
Home disciplines | Geography | Computing, Statistics |
Software focus | Graphical User Interface | Command line |
Reproducibility | Minimal | Maximal |
Traditionally, spatial data is described by two basic data models:
Geographic coordinates
Projected coordinates
Software databases:
File formats:
Name | Extension | Model |
---|---|---|
ESRI Shapefile | .shp (the main file) | Partially open |
GeoJSON | .geojson | Open |
KML | .kml | Open |
GPX | .gpx | Open |
FlatGeobuf | .fgb | Open |
Selected spatial file formats
Name | Extension | Model |
---|---|---|
GeoTIFF | .tif/.tiff | Open |
Arc ASCII | .asc | Open |
SQLite/SpatiaLite | .sqlite | Open |
ESRI FileGDB | .gdb | Proprietary |
GeoPackage | .gpkg | Open |
GDAL:
SpatioTemporal Asset Catalog (STAC) – a general description format for spatiotemporal data that is used to describe a variety of datasets on cloud platforms including imagery, synthetic aperture radar (SAR) data, and point clouds.
Cloud Optimized GeoTIFF (COG) – raster objects saved as COGs can be hosted on HTTP servers, so other people can read only parts of the file without downloading the whole file
Other new file formats – GeoParquet, GeoArrow, Zarr
Used for a various task related to spatial raster data.
It can be divided into four groups:
Based on the input data type:
Based on the goal of the analysis:
(incomplete lists)
Visit https://cran.r-project.org/view=Spatial to get an overview of different spatial tasks that can be solved using R.
Simple feature collection with 177 features and 10 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -180 ymin: -89.9 xmax: 180 ymax: 83.64513
Geodetic CRS: WGS 84
# A tibble: 177 × 11
iso_a2 name_l…¹ conti…² regio…³ subre…⁴ type area_…⁵ pop lifeExp gdpPe…⁶
* <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 FJ Fiji Oceania Oceania Melane… Sove… 1.93e4 8.86e5 70.0 8222.
2 TZ Tanzania Africa Africa Easter… Sove… 9.33e5 5.22e7 64.2 2402.
3 EH Western… Africa Africa Northe… Inde… 9.63e4 NA NA NA
4 CA Canada North … Americ… Northe… Sove… 1.00e7 3.55e7 82.0 43079.
5 US United … North … Americ… Northe… Coun… 9.51e6 3.19e8 78.8 51922.
6 KZ Kazakhs… Asia Asia Centra… Sove… 2.73e6 1.73e7 71.6 23587.
7 UZ Uzbekis… Asia Asia Centra… Sove… 4.61e5 3.08e7 71.0 5371.
8 PG Papua N… Oceania Oceania Melane… Sove… 4.65e5 7.76e6 65.2 3709.
9 ID Indones… Asia Asia South-… Sove… 1.82e6 2.55e8 68.9 10003.
10 AR Argenti… South … Americ… South … Sove… 2.78e6 4.30e7 76.3 18798.
# … with 167 more rows, 1 more variable: geom <MULTIPOLYGON [°]>, and
# abbreviated variable names ¹name_long, ²continent, ³region_un, ⁴subregion,
# ⁵area_km2, ⁶gdpPercap
# ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
class : SpatRaster
dimensions : 457, 465, 1 (nrow, ncol, nlyr)
resolution : 0.0008333333, 0.0008333333 (x, y)
extent : -113.2396, -112.8521, 37.13208, 37.51292 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : srtm.tif
name : srtm
min value : 1024
max value : 2892
“world’s largest spider web” (CC BY-NC-SA 2.0) by bluehurricane
Also see: tmap_mode("view")
, {mapview}
Internal and external reasons
RStudio: File > New Project > New Directory -> New Project -> …
Absolute vs relative paths
Also: clear environment + restart R
Why: to ask a question; to report a bug; to fix a bug; to showcase some examples; …
Input: minimal code allowing to reproduce your problem/example (strip away everything that is not directly related to your problem)
Output: resulting runnable code + output as Markdown (including code results and plots) + (optionally) session info
renv::init(
) to initialize a new project-local environment with a private R libraryrenv::snapshot()
to save the state of the project library to the lockfile (renv.lock
)renv::snapshot()
again to save the state of your project or renv::restore()
to revert to the previous state as encoded in the lockfilehttps://github.com/Robinlovelace/geocompr/blob/main/06-raster-vector.Rmd
Before new changes:
After new changes:
R packages may serve many purposes…
Create a package template:
Subset of other useful {usethis} functions:
https://r-pkgs.org/, https://indrajeetpatil.github.io/awesome-r-pkgtools/
R/
)devtools::load_all()
function, which loads new/modified functions into R sessiondevtools::document()
devtools::check()
Also see: https://mybinder.org/v2/gh/robinlovelace/geocompr/main?urlpath=rstudio
Also see: Create a Dockerfile from renv.lock – https://github.com/ThinkR-open/dockerfiler
Issue: …but it works on my computer
CI/CD: continuous integration (CI) and continuous deployment (CD)
https://github.com/Robinlovelace/geocompr/blob/main/.github/workflows/main.yaml