├── README.md └── Spatial.md /README.md: -------------------------------------------------------------------------------- 1 | ## CRAN Task View: Analysis of Spatial Data 2 | 3 | **URL:** 4 | 5 | **Source file:** [Spatial.md](Spatial.md) 6 | 7 | **Contributions:** Suggestions and improvements for this task view are very 8 | welcome and can be made through issues or pull requests here on GitHub or 9 | via e-mail to the maintainer address. For further details see the 10 | [Contributing](https://github.com/cran-task-views/ctv/blob/main/Contributing.md) 11 | guide. All contributions must adhere to the 12 | [code of conduct](https://github.com/cran-task-views/ctv/blob/main/CodeOfConduct.md). 13 | 14 | ## Minimum standards 15 | 16 | We encourage the packages authors to follow minimum standards for their package to be included in the Spatial CRAN Task View: 17 | 18 | - The package must be related to spatial data reading/writing, handling, processing, or analyzing 19 | - The package should be actively maintained 20 | - The package should have extended documentation in the form of a vignette, blog post, scientific article, technical report, or video. In other words, there should be a way for new users to get started with using the package 21 | 22 | Packages already listed, but without extended documentation are encouraged to add more documentation in a forthcoming revision of the package. -------------------------------------------------------------------------------- /Spatial.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Spatial 3 | topic: Analysis of Spatial Data 4 | maintainer: Roger Bivand, Jakub Nowosad 5 | email: Roger.Bivand@nhh.no, nowosad.jakub@gmail.com 6 | version: 2025-06-02 7 | source: https://github.com/cran-task-views/Spatial/ 8 | --- 9 | 10 | Base R includes many functions that can be used for reading, 11 | visualising, and analysing spatial data. The focus in this view is on 12 | "geographical" spatial data, where observations can be identified with 13 | geographical locations, and where additional information about these 14 | locations may be retrieved if the location is recorded with care. 15 | 16 | Base R functions are complemented by contributed packages provided as 17 | source packages, and as ready-to-run binary packages for Windows and 18 | macOS (Intel 64-bit and Apple Silicon arm64 architectures). Information 19 | about source installs of packages using software external to R may be 20 | found at the end of this page. This task view covers the current status 21 | of contributed packages available from CRAN. 22 | 23 | The contributed packages address two broad areas: moving spatial data 24 | into and out of R including coordinate transformation, and analysing 25 | spatial data in R. Because the contributed packages constitute an evolving 26 | ecosystem, there are several points of entry for users looking for help 27 | and information. Two informal organisations curate websites: 28 | [r-spatial](https://r-spatial.org/) with a hyphen, and 29 | [rspatial](https://rspatial.org/) without. R-spatial is more generally 30 | geo-informatics based, grew from the legacy `r pkg("sp")` package and 31 | is now clearly aligned with the modern `r pkg("sf", priority="core")` and 32 | `r pkg("stars", priority="core")` packages. Rspatial has grown from the 33 | `r pkg("raster")` package, now moving towards the modern 34 | `r pkg("terra", priority="core")` package. It is also worth noting the 35 | wealth of online book projects, which may be helpful for users seeking 36 | an introduction, including 37 | [Geocomputation with R](https://r.geocompx.org/index.html). 38 | 39 | Specific questions or issues may be raised where 40 | `packageDescription()$BugReports` returns an URL for bug 41 | reports or issues (where `` is the 42 | name of the package as a string), or directly with package 43 | maintainers by email. Use may also be made of 44 | the [R-SIG-Geo](https://stat.ethz.ch/mailman/listinfo/R-SIG-Geo/) 45 | mailing-list after subscription, or of 46 | [Stack Overflow](https://stackoverflow.com) with appropriate tags, or of 47 | [Stack Exchange](https://gis.stackexchange.com/). Using the 48 | `#rspatial` tag on [Mastodon](https://joinmastodon.org/) 49 | may also be worth trying, or browsing traffic using that tag (among others); 50 | BlueSky currently is emerging. 51 | 52 | The packages in this view can be roughly structured into the following 53 | topics. If you think that some package is missing from the list, please 54 | e-mail the maintainer or submit an issue or pull request in the GitHub 55 | repository linked above. 56 | 57 | Classes for spatial data and metadata 58 | ------------------------------------- 59 | 60 | Many of the packages for handling and analysing spatial data use shared classes to 61 | reduce duplication of effort. Up until 2016, the `r pkg("sp")` package provided 62 | shared classes for spatial vector and raster data, but the representations used 63 | preceded more modern and efficient international standards for spatial vector data. 64 | From the release of `r pkg("sf", priority = "core")`, these modern vector 65 | representations are to be preferred. For spatial raster data, the representations 66 | proposed in `r pkg("stars", priority = "core")` and `r pkg("terra", priority = "core")` 67 | suit overlapping but slightly different requirements. Conversion between objects 68 | of classes defined by `r pkg("sf")`, `r pkg("stars")`, `r pkg("terra")` and the legacy 69 | `r pkg("sp")` packages are available, and are described in [Conversions between different 70 | spatial classes in R](https://geocompx.org/post/2021/spatial-classes-conversion/). 71 | 72 | Complementary initiatives are ongoing to support better handling of 73 | geographic metadata in R. 74 | 75 | ### Spatial data - general 76 | 77 | - `r pkg("sf", priority = "core")` is a CRAN package for spatial vector data, 78 | providing Simple Features 79 | for R, in compliance with the [OGC Simple 80 | Feature](http://www.opengeospatial.org/standards/sfa) standard. The 81 | development of the package was supported by the [R 82 | Consortium](https://www.r-consortium.org/). It provides simple 83 | features access for vector data, and as such is a modern 84 | implementation and standardization of parts of the legacy 85 | `r pkg("sp")` package. `r pkg("sf")` is documented in an [R 86 | Journal](https://journal.R-project.org/archive/2018/RJ-2018-009/index.html) 87 | article. `r pkg("sf")` uses the [PROJ](https://proj.org/), [GEOS](https://libgeos.org/) 88 | and [GDAL](https://gdal.org/) external software 89 | libraries, which must be available for source installs together with 90 | other external software libraries that they in turn depend on. 91 | - `r pkg("stars", priority = "core")` is being actively developed and 92 | was initially supported by the [R Consortium](https://www.r-consortium.org/); 93 | it provides for 94 | spatiotemporal data in the form of dense arrays. It supercedes the 95 | `r pkg("spacetime")` package, which 96 | extended the shared classes defined in `r pkg("sp")` for 97 | spatio-temporal data (see [Spatio-Temporal Data in 98 | R](http://www.jstatsoft.org/v51/i07)). `r pkg("stars")` uses PROJ and 99 | GDAL through `r pkg("sf")`. 100 | - `r pkg("terra", priority = "core")` provides classes for spatial vector and 101 | raster data, linking directly to PROJ, GDAL and GEOS. 102 | access to GDAL functionality for R packages. 103 | - `r pkg("gdalraster")` provides API bindings to GDAL. Since `r pkg("gdalraster")` 104 | 2.0.0, bindings are provided for both the Raster and Vector [APIs](https://gdal.org/en/stable/api/index.html), 105 | the Geometry API ([GEOS](https://libgeos.org/) via GDAL headers) and Spatial 106 | Reference Systems API ([PROJ](https://proj.org/) via GDAL). Bindings are 107 | also provided for the low-level Virtual Systems Interface ([VSI](https://gdal.org/en/stable/api/cpl.html#cpl-vsi-h)) 108 | which abstracts file system operations and binary I/O on URLs, cloud storage 109 | services, compressed files (.zip, .gz, .tar, .tar.gz, .7z archives) and 110 | in-memory files, as well as regular file systems. Calling signatures 111 | resemble the native C, C++ and Python APIs provided by the GDAL project. 112 | - The `r pkg("vapour")` package also offers low-level access to GDAL 113 | functionality for R packages. 114 | - The `r pkg("spatstat", priority = "core")` contains classes suited to the 115 | analysis of point patterns, and may be coerced to and from `"sf"`, `"stars"` 116 | and other spatial classes. 117 | 118 | 119 | ### Raster data 120 | 121 | - `r pkg("terra", priority = "core")` is a re-implementation of 122 | `r pkg("raster")` functionality and introducing new S4 classes for raster and 123 | vector data. See the [manual and 124 | tutorials](https://rspatial.org/terra/) to get started. 125 | `r pkg("terra")` is very similar to the `r pkg("raster")` package; but 126 | `r pkg("terra")` is simpler and faster. 127 | - `r pkg("stars", priority = "core")` provides for spatiotemporal data in the 128 | form of dense arrays, with space and time being array dimensions. 129 | Examples include socio-economic or demographic data, environmental 130 | variables monitored at fixed stations, time series of satellite 131 | images with multiple spectral bands, spatial simulations, and 132 | climate model results. 133 | - The `r pkg("gdalcubes")` package also provides classes for data cubes, 134 | including proxy data cubes, it links to PROJ, GDAL and NetCDF4. 135 | - `r pkg("gdalraster")` provides an R implementation of the [GDAL Raster Data 136 | Model](https://gdal.org/en/stable/user/raster_data_model.html), along with 137 | several utilities and algorithms for processing and analyzing raster data. 138 | 139 | ### Geographic metadata 140 | 141 | - `r pkg("geometa")` provides classes and methods to write 142 | geographic metadata following the ISO and OGC metadata standards 143 | (ISO 19115, 19110, 19119) and export it as XML (ISO 19139) for later 144 | publication into metadata catalogues. Reversely, geometa provides a 145 | way to read ISO 19139 metadata into R. The package extends 146 | `r pkg("sf")` to provide GML (ISO 19136) representation 147 | of geometries. 148 | - `r pkg("ncdf4")` provides read and write functions for 149 | handling metadata (CF conventions) in the self-described NetCDF 150 | format. 151 | - `r pkg("CFtime")` encapsulates the CF time coordinate and allows to deal 152 | with the different CF calendars 153 | 154 | Reading and writing spatial data 155 | -------------------------------- 156 | 157 | Spatial data is most often represented by one of two data models, 158 | vector or raster, and both models have many of their own file formats. 159 | [GDAL (Geospatial Data Abstraction Library)](https://gdal.org/) is a (non-R) 160 | library that provides a unified way to read and write hundreds of 161 | spatial data formats. Formats supported by GDAL include both OGC standard 162 | data formats (e.g., GeoPackage) and proprietary formats (e.g., ESRI Shapefile). 163 | GDAL is used by a large number of GIS software and also many R packages, 164 | such as `r pkg("sf")`, `r pkg("terra")`, and `r pkg("vapour")`, and the 165 | `r pkg("gdalraster")` package explicitly implements the GDAL [Raster](https://gdal.org/en/stable/user/raster_data_model.html) 166 | and [Vector](https://gdal.org/en/stable/user/vector_data_model.html) Data 167 | Models. This allows us to read and write spatial data in R from and to various 168 | spatial file formats. Important note: CRAN offers binary versions of packages 169 | `r pkg("gdalraster")`, `r pkg("sf")`, `r pkg("terra")`, and `r pkg("vapour")` 170 | for Windows and macOS, that contain specific GDAL version with a subset of 171 | possible data source drivers. If other drivers are needed, you need to either 172 | use other conversion utilities or install these packages from the source against 173 | a version of GDAL with the required drivers. 174 | 175 | In the past, `r rforge("rgdal")` and `r pkg("raster")` (through `r rforge("rgdal")`) 176 | were recommended for reading and writing of spatial data in R. 177 | However, due to [the retirement of rgdal on 16 October 2023](https://stat.ethz.ch/pipermail/r-sig-geo/2023-October/029350.html) 178 | new projects should not use it, and existing projects should implement migration 179 | to the packages mentioned in the previous paragraph. In addition, `r rforge("rgeos")` 180 | and `r rforge("maptools")` were archived at the same time. Further details and links 181 | may be found in [project reports](https://r-spatial.github.io/evolution/) on the evolution 182 | project. From October 2023, `r pkg("sp")` only uses methods 183 | from `r pkg("sf")` in place of those from `r rforge("rgdal")` for projection 184 | and access to the underlying definitions of coordinate reference systems. 185 | 186 | ### Reading and writing spatial data - data formats 187 | 188 | Other packages provide facilities to read and write spatial data, 189 | dealing with open standard formats or proprietary formats. 190 | 191 | *Open formats* 192 | 193 | - *Well-Known Text (WKT) / Well-Known Binary (WKB):* These standards are 194 | part of the OGC Simple Feature specification. Both WKT/WKB formats are 195 | supported by the `r pkg("sf")` package that implements the whole 196 | OGC Simple Feature specification in R. Additionally, `r pkg("wk")` and 197 | `r pkg("wkutils")` may be used to parse well-known binary and 198 | well-known text representation of geometries to and from R-native formats. 199 | - *GeoJSON:* An rOpenSci [blog entry](http://ropensci.org/blog/blog/2016/11/22/geospatial-suite) 200 | describes a GeoJSON-centred approach to reading GeoJSON and WKT data. 201 | The entry lists `r pkg("geojson")`, and `r pkg("geojsonio")`, among others. 202 | The GeoJSON format can also be read and written with `r pkg("gdalraster")`, 203 | `r pkg("sf")`, `r pkg("terra")`, and `r pkg("vapour")`. 204 | - *Geographic Markup Language (GML):* GML format can be read and written 205 | with `r pkg("sf")`. Additional GML native reader and writer is provided 206 | by `r pkg("geometa")` model with bindings to the `r pkg("sf")` classes, 207 | for extension of geographic metadata with GML data and metadata 208 | elements (GML 3.2.1 and 3.3) and interfacing OGC web-services 209 | in `r pkg("ows4R")` package. 210 | - *NetCDF files:* NetCDF files can be read and write with 211 | `r pkg("ncdf4")` or `r pkg("RNetCDF")`. Additionally, both `r pkg("terra")` 212 | and `r pkg("stars")` have capabilities for reading and writing NetCDF files. 213 | - *LAS / LAX:* These file formats are designed to work with lidar point 214 | cloud data and can be read/write with `r pkg("lidR")`. 215 | 216 | *Proprietary Data Formats* 217 | 218 | - *ESRI formats:* Many of spatial data saved into ESRI file formats 219 | can be read with GDAL, and thus also with `r pkg("sf")`, 220 | `r pkg("terra")`, and `r pkg("vapour")`. Additionally, 221 | `r pkg("shapefiles")` reads and writes ESRI ArcGIS/ArcView shapefiles. 222 | Additionally, `r pkg("maps")` (with `r pkg("mapdata")` and 223 | `r pkg("mapproj")`) provides a legacy tool to access to the same kinds 224 | of geographical databases as S. 225 | - *Others:* The `r pkg("gmt")` package gives a simple interface 226 | between GMT map-making software and R. 227 | 228 | ### Reading and writing spatial data - GIS Software connectors 229 | 230 | - *PostGIS:* The `r pkg("rpostgis")` package provides additional functions 231 | to the `r pkg("RPostgreSQL")` package to interface R with a 232 | 'PostGIS'-enabled database, as well as convenient wrappers to 233 | common 'PostgreSQL' queries. It is documented in an 234 | [R Journal](https://journal.R-project.org/archive/2018/RJ-2018-025/index.html) 235 | article. 236 | `r pkg("sf")` also provides an R interface to PostGIS, 237 | for both reading and writing, through GDAL. 238 | - *GRASS GIS:* Integration with version 7.\* and 8.\* of the leading open source GIS, 239 | GRASS GIS, is provided in CRAN package `r pkg("rgrass")`, which uses `r pkg("terra")` for file transfer. 240 | - *SAGA GIS:* `r pkg("RSAGA")` and `r pkg("Rsagacmd")` offer shell-based 241 | wrapper for SAGA GIS commands. 242 | - *QGIS:* QGIS version 2 was supported by RQGIS 243 | (`r github("r-spatial/RQGIS")`). Using QGIS processing algorithms is currently 244 | supported by `r pkg("qgisprocess")`, which uses the standalone 245 | 'qgis_process' command-line utility from QGIS (use 246 | recent QGIS versions; may work since >= 3.16). Both native QGIS and third-party 247 | (plugin) processing providers are supported, i.e. GRASS, SAGA, GDAL, ... 248 | - *WhiteboxTools:* `r pkg("whitebox")` is an R frontend for 249 | the WhiteboxTools software. 250 | - *ArcGIS:* `r pkg("RPyGeo")` is a wrapper for Python access 251 | to the ArcGIS GeoProcessor. The ESRI company also offers their 252 | own package (`r github("R-ArcGIS/r-bridge")`) that allows transferring data 253 | from ArcGIS to R. 254 | - *DuckDB*: `r pkg("duckspatial")` is a package that allows and simplifies the process of writing 255 | and reading vector data into a DuckDB database through the SPATIAL extension. 256 | - Various GIS Software, including Orfeo ToolBox and SAGA GIS, can also be 257 | connected to R using `r pkg("link2GI")`. 258 | - *Orfeo ToolBox* segmentation module: `r pkg("OTBsegm")` simplifies the process of applying 259 | unsupervised segmentation algorithms available in *Orfeo Toolbox* via the `r pkg("link2GI")` 260 | 261 | ### Specific geospatial data sources of interest 262 | 263 | - `r pkg("rnaturalearth")` package facilitates interaction with 264 | [Natural Earth](http://www.naturalearthdata.com/) map data. It includes 265 | functions to download a wealth of Natural Earth vector and raster data, 266 | including cultural (e.g., country boundaries, airports, roads, railroads) 267 | and physical (e.g., coastline, lakes, glaciated areas) datasets. 268 | - `r pkg("elevatr")` provides access to elevation data from several web services. 269 | - Historical country boundaries (1886-today) can be obtained 270 | from the `r pkg("cshapes")`. 271 | - `r pkg("marmap")` package is designed for downloading, plotting, 272 | and manipulating bathymetric and topographic data in R. It allows to query 273 | the ETOPO1 bathymetry and topography database hosted by the NOAA, 274 | use simple latitude-longitude-depth data in ASCII format, and take 275 | advantage of the advanced plotting tools available in R to build 276 | publication-quality bathymetric maps (see the 277 | [PLOS](http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0073051) 278 | paper). 279 | - `r pkg("tidycensus")` provides access to US Census Bureau data in a 280 | tidy format, including the option to bind the data spatially on import. 281 | - `r pkg("tigris")` provides access to cartographic elements provided by 282 | the US Census Bureau TIGER, including cartographic boundaries, roads, 283 | and water. 284 | - `r pkg("rgbif")` package is used to access Global Biodiversity 285 | Information Facility (GBIF) occurrence data 286 | - `r pkg("geonames")` is an interface to the 287 | [www.geonames.org](http://www.geonames.org/) service. 288 | - `r pkg("osmdata")` is an R package for accessing relatively 289 | small datasets from OpenStreetMap (OSM), delivered via the Overpass API. 290 | `r pkg("osmextract")` matches, downloads, converts, and reads 291 | OpenStreetMap data covering large areas, obtained from Geofabrik 292 | and other providers. 293 | - `r pkg("osmapiR")` is an R interface to the [OpenStreetMap API](https://wiki.openstreetmap.org/wiki/API_v0.6) for 294 | fetching and saving all kinds of data from/to the OpenStreetMap database, 295 | including map objects, GPS traces, notes, changesets, and users. 296 | - `r pkg("OpenStreetMap")` gives access to open street map raster images. 297 | - `r pkg("giscoR")` provides access to spatial elements provided by 298 | GISCO - Eurostat, including boundary files of countries, NUTS regions, 299 | municipalities, and other spatial objects. 300 | - `r pkg("chilemapas")` provides access to spatial data of political 301 | and administrative divisions of Chile. 302 | - `r pkg("geobr")` provided easy access to official spatial data sets of 303 | Brazil for multiple geographies and years. 304 | - `r pkg("geouy")` loads and process geographic information for Uruguay. 305 | - `r pkg("RCzechia")` downloads spatial boundary files of administrative regions 306 | and other spatial objects of the Czech Republic. 307 | - `r pkg("rgugik")` allows to search and retrieve data from Polish Head 308 | Office of Geodesy and Cartography ("GUGiK"). 309 | - `r pkg("mapSpain")` downloads spatial boundary files of administrative 310 | regions and other spatial objects of Spain. 311 | - `r pkg("mapme.biodiversity")` allows to download and process a number open 312 | datasets related to biodiversity conservation providing efficient routines 313 | and parallelization options. Datasets include among others the 314 | [Global Forest Watch](https://www.globalforestwatch.org/), 315 | [ESA/Copernicus Landcover](https://land.copernicus.eu/global/products/lc), 316 | [WorldClim](https://www.worldclim.org/) and 317 | [NASA FIRMS](https://firms.modaps.eosdis.nasa.gov/active_fire/). 318 | - `r pkg("terrainr")` provides an interface to the 319 | [United States Geological Survey's National Map services](https://apps.nationalmap.gov/services/), 320 | providing elevation data and orthoimagery along other basemap tiles 321 | for the United States. 322 | - `r pkg("geodata")` facilitates access to climate, elevation, soil, crop, 323 | species occurrence, and administrative boundary data, and is a successor of 324 | the `getData()` function from the `r pkg("raster")` package. 325 | - `r pkg("forestdata")` allows to download forest and land cover data from 326 | various sources, includying forest inventory data, forest cover maps, and 327 | global canopy height models. 328 | 329 | ### Interfaces to Spatial Web-Services 330 | 331 | Some R packages focused on providing interfaces to web-services and web tools 332 | in support of spatial data management. Here follows a first tentative 333 | (non-exhaustive) list: 334 | 335 | - `r pkg("ows4R")` is a package that intends to provide an R interface 336 | to OGC standard Web-Services. It is in active development and currently 337 | support interfaces to the 338 | Web Feature Service (WFS) for vector data access, with binding to the 339 | `r pkg("sf")` package, and the Catalogue Service (CSW) for geographic 340 | metadata discovery and management (including transactions), with binding 341 | to the `r pkg("geometa")` package. 342 | - `r pkg("geosapi")` is an R client for the [GeoServer](http://geoserver.org) 343 | REST API, an open source implementation used widely for serving 344 | spatial data. 345 | - `r pkg("geonapi")` provides an interface to the 346 | [GeoNetwork](https://geonetwork-opensource.org/) legacy API, 347 | an open source catalogue for managing geographic metadata. 348 | 349 | ### Remote sensing 350 | 351 | - `r pkg("rstac")` provides functions to access, search and download 352 | spacetime earth observation data via [SpatioTemporal Asset Catalogs](https://stacspec.org). 353 | This package supports the version 1.0.0 (and older) of the 354 | [STAC specification](https://github.com/radiantearth/stac-spec). 355 | - The `r pkg("rsi")` package provides an interface to the 356 | [Awesome Spectral Indices](https://github.com/awesome-spectral-indices/awesome-spectral-indices) 357 | project. It also provides functions to download, mask, and composite data 358 | from [SpatioTemporal Asset Catalogs](https://stacspec.org), with a particular 359 | focus on satellite imagery. 360 | - The `r pkg("sits")` is an end-to-end toolkit for land use and land cover 361 | classification using big Earth observation data, based on machine learning 362 | methods applied to satellite image data cubes. 363 | - The `r pkg("landsat")` package with accompanying 364 | [JSS paper](http://www.jstatsoft.org/v43/i04) provides tools for exploring 365 | and developing correction tools for remote sensing data. 366 | - `r github("rspatial/luna")` has tools for acquiring and processing satellite 367 | remote sensing data from NASA's LANDSAT and MODIS data sources. 368 | `r pkg("MODISTools")` also provides an interface to the 369 | [MODIS Land Products Subsets](https://modis.ornl.gov/data/modis_webservice.html) 370 | web services. 371 | `r pkg("modisfast")`, on its side, provides an interface to some MODIS, VIIRS 372 | and GPM [OPeNDAP](https://www.opendap.org/) servers, enabling to subset the datacubes 373 | directly at the download phase. 374 | - `r pkg("rgee")` is an [Earth Engine](https://earthengine.google.com/) 375 | client library for R. All of the 'Earth Engine' API classes, modules, 376 | and functions are made available. Additional functions implemented include 377 | importing (exporting) of Earth Engine spatial objects, 378 | extraction of time series, interactive map display, 379 | assets management interface, and metadata display. 380 | 381 | Handling spatial data 382 | --------------------- 383 | 384 | ### Data processing - general 385 | 386 | - `r pkg("sf")` provides an interface to spatial geometry functions using 387 | the [GEOS](https://libgeos.org/) and [S2](https://s2geometry.io/) libraries; S2 388 | is bundled in the `r pkg("s2")` package which `r pkg("sf")` methods use for 389 | topological predicates and operations on spherical or elliptical coordinates by default. 390 | - `r pkg("stars")` contains tools for manipulating raster and vector 391 | data cubes. 392 | - `r pkg("terra")` package introduces many GIS methods for spatial vector 393 | and raster data. 394 | - The `r github("cran/gdalUtils")` (see 395 | ) 396 | and `r pkg("gdalUtilities")` packages provide 397 | wrappers for the Geospatial Data Abstraction Library (GDAL) Utilities. 398 | - `r pkg("gdalraster")` provides access to GDAL utilities and algorithms via 399 | API bindings, including GDAL facilities for [vector overlay operations](https://en.wikipedia.org/wiki/Vector_overlay). 400 | - The `r pkg("geos")` high-performance bindings to the GEOS library, based on 401 | `r pkg("libgeos")`; the latter bundles a frozen copy of GEOS, and does not 402 | link to system versions, which may possibly be different versions of GEOS. 403 | - `r pkg("rmapshaper")` is a wrapper around the 'mapshaper' 'JavaScript' 404 | library to perform topologically-aware polygon simplification and other 405 | operations such as clipping, erasing, dissolving, and converting 406 | 'multi-part' to 'single-part' geometries. 407 | - `r pkg("gdistance")` and `r pkg("spaths")` provide functions to calculate distances and 408 | routes on geographic grids. 409 | - `r pkg("geosphere")` permits computations of distance and area to be 410 | carried out on spatial data in geographical coordinates. 411 | - `r pkg("dggridR", priority = "core")` provides a discrete global grid system 412 | via DGGRID. These grids are useful for spatial statistics because 413 | they tile the Earth with _equally_-sized hexagons, triangles, or diamonds. 414 | - `r pkg("cshapes")` package provides functions for calculating distance 415 | matrices (see [Mapping and Measuring Country Shapes](http://journal.R-project.org/archive/2010-1/RJournal_2010-1_Weidmann+Skrede~Gleditsch.pdf)). 416 | - `r pkg("magclass")` offers a data class for increased interoperability 417 | working with spatial-temporal data together with corresponding functions 418 | and methods (conversions, basic calculations and basic data manipulation). 419 | - The `r pkg("trip")` package extends spatial classes to permit the 420 | accessing and manipulating of spatial data for animal tracking. 421 | 422 | 423 | ### Data cleaning 424 | 425 | - `r pkg("sf")` has a built-in functions `st_is_valid` to check whether 426 | a sf geometry is valid and `st_make_valid` to fix invalid geometry (from GEOS 3.8). 427 | - `r pkg("lwgeom")` may also be used to facilitate handling and reporting 428 | of topology errors and geometry validity issues 429 | in sf objects. 430 | 431 | ### Data processing - specific 432 | 433 | - The `r pkg("areal")` package can be used to interpolate overlapping 434 | but incongruent polygons, also known as areal weighted interpolation. 435 | - The `r pkg("centerline")` package can be used for centerline (or median-axis) estimation of closed polygons, 436 | such as lakes, landslides, or rivers. The package also 437 | provides extensions to `r pkg("ggplot2")`, allowing users to place `geom_text` and `geom_label` at the center of a spatial 438 | polygon, which can be useful for map-making. 439 | - The `r pkg("qualmap")` package can be used to digitize qualitative GIS data. 440 | - The `r pkg("exactextractr")` for fast and accurate summary of raster values 441 | on polygonal areas (known as zonal statistics). 442 | 443 | ### Spatial sampling 444 | 445 | - `r pkg("spsurvey")` provides functions to select generalized 446 | random-tessellation stratified (GRTS) probability samples 447 | and analyze survey data. 448 | - `r pkg("Spbsampling")` allows selecting probability samples well spread 449 | over the population of interest, in any dimension and using 450 | any distance function. 451 | - `r pkg("spatialsample")` is a member of the tidymodels family of packages 452 | and contains functions and classes for spatial resampling to use with 453 | `r pkg("rsample")`. 454 | - `r pkg("MBHdesign")` provides spatially survey balanced designs using the 455 | quasi-random number method. 456 | 457 | Visualizing spatial data 458 | ------------------------ 459 | 460 | ### Base visualization packages 461 | 462 | - Packages such as `r pkg("sf")`, `r pkg("stars")`, `r pkg("terra")`, 463 | and `r pkg("rasterVis")` provide basic visualization methods through 464 | the generic plot function. 465 | - `r pkg("classInt", priority = "core")` package provides functions for 466 | choosing class intervals for thematic cartography. 467 | - Currently, the grDevices package (included with the R installation) 468 | contains a large number of color palettes that can be accessed with 469 | the `hcl.colors` and `palette.colors` functions; see also New features in this 470 | [blog](https://developer.r-project.org/Blog/public/2019/11/21/a-new-palette-for-r/index.html). 471 | Some of these color palettes can be also retrieved using separate packages, 472 | such as `r pkg("RColorBrewer")`, `r pkg("viridis")`, 473 | or `r pkg("rcartocolor")`. 474 | 475 | ### Thematic cartography packages 476 | 477 | - `r pkg("tmap")` package accepts most spatial data classes and provides 478 | a modern basis for thematic mapping using a Grammar of Graphics syntax. 479 | It also allows for interactive spatial data mapping. 480 | - `r pkg("mapsf")` package allows various cartographic representations 481 | such as proportional symbols, choropleth, or typology maps; it accepts sf 482 | (`r pkg("sf")`) and SpatRaster (`r pkg("terra")`) objects 483 | - `r pkg("ggplot2")` package has a built-in support for sf objects with the 484 | `geom_sf` function and additional support for stars object is available 485 | through the `geom_stars` function available in the `r pkg("stars")` package. 486 | Its spatial visualization capabilities can be further extended with 487 | `r pkg("ggspatial")`, which adds support for more spatial classes 488 | (including classes from the raster package), allows adding north arrows 489 | and scale bars, etc. 490 | - The `r pkg("mapmisc")` package is a minimal, light-weight set of tools 491 | for producing nice-looking maps in R, with support for map projections. 492 | - Additional processing and mapping functions are available in 493 | `r pkg("PBSmapping")` package; `r pkg("PBSmodelling")` provides 494 | modelling support. In addition, `r pkg("GEOmap")` provides mapping 495 | facilities directed to meet the needs of geologists and uses 496 | the `r pkg("geomapdata")` package. 497 | 498 | ### Packages based on web-mapping frameworks 499 | 500 | - `r pkg("mapview")` and `r pkg("leaflet")` packages provide methods to 501 | view spatial objects interactively, usually on a web mapping base. 502 | Additionally, `r pkg("tmap")` has a view mode that allows for interactive 503 | spatial data mapping. 504 | - `r pkg("mapdeck")` package provides a mechanism to plot interactive maps 505 | through javascript libraries 'Mapbox GL' and 'Deck.gl'. 506 | - `r pkg("RgoogleMaps")` package for accessing Google Maps(TM) may be 507 | useful if the user wishes to place a map backdrop behind other displays. 508 | - `r pkg("ggmap")` may be used for spatial visualization with Google Maps 509 | and OpenStreetMap. 510 | - `r pkg("mapedit")` provides an R shiny widget based on `r pkg("leaflet")` 511 | for editing or creating sf geometries. 512 | 513 | ### Building Cartograms 514 | 515 | - `r pkg("cartogram")` package allows for constructions of a continuous 516 | area cartogram by a rubber sheet distortion algorithm, non-contiguous 517 | area cartograms, and non-overlapping circles cartogram. 518 | - `r pkg("geogrid")` package turns polygons into rectangular or hexagonal 519 | cartograms. 520 | - `r pkg("micromap")` package provides linked micromaps using ggplot2. 521 | - `r pkg("recmap")` package provides rectangular cartograms with rectangle 522 | sizes reflecting for example population. 523 | - `r pkg("geogrid")` turns spatial polygons into regular or hexagonal grids. 524 | `r pkg("statebins")` provides a simple binning approach to US states. 525 | 526 | Analyzing spatial data 527 | ---------------------- 528 | 529 | The division of spatial statistics into three partly overlapping 530 | areas: point pattern analysis, geostatistics and the analysis of 531 | areal/lattice data, is widely accepted. However, areal data 532 | analysis can be split into disease mapping and spatial regression 533 | (also partly overlapping). In addition, ecological analyses often 534 | approach spatial data in particular ways, giving rise to a specific 535 | topical cluster of packages. Moreover, machine learning for spatial data 536 | is a growing area of interest, and there are packages that 537 | provide tools for this. 538 | All of these approaches to analysing spatial data 539 | treat the spatial relationships between observations as a way of exploring 540 | and making use of important sources of information about the observations over 541 | and above what is known when assuming that they are independent of each other. 542 | 543 | ### Point pattern analysis 544 | 545 | Point pattern analysis examines the distance relationships between observed points, 546 | where the set of observations is expected to encompass all such entities in the 547 | study area. 548 | 549 | - `r pkg("spatstat", priority = "core")` is a family of R packages for analysing 550 | spatial point pattern data (and other kinds of spatial data). It has extensive 551 | capabilities for exploratory analysis, statistical modelling, simulation and 552 | statistical inference. It allows freedom in defining the region(s) 553 | of interest, and makes extensions to marked processes and spatial 554 | covariates. Its strengths are model-fitting and simulation, and it has a 555 | useful [homepage](http://www.spatstat.org/); it is 556 | [actively developed](https://github.com/spatstat/spatstat). It is the only package 557 | that will enable the user to fit inhomogeneous point process models with 558 | interpoint interactions. 559 | - The `r pkg("splancs")` package allows 560 | point data to be analysed within a polygonal region of interest, and 561 | covers many methods, including 2D kernel densities. 562 | - The `r pkg("spatial")` package 563 | is a recommended package shipped with base R, and contains several core functions, 564 | including an implementation of Khat by its author, Prof. Ripley. 565 | - The `r pkg("spatgraphs")` package provides graphs, graph visualisation 566 | and graph based summaries to be used with spatial point pattern analysis. 567 | - The `r pkg("smacpod")` package provides various statistical 568 | methods for analyzing case-control point data. The methods available 569 | closely follow those in chapter 6 of Applied Spatial Statistics for 570 | Public Health Data by Waller and Gotway (2004). 571 | - `r pkg("ecespa")` provides wrappers, functions and data for 572 | spatial point pattern analysis, used in the book on Spatial Ecology of 573 | the ECESPA/AEET. The functions for binning points on grids in 574 | - `r pkg("ads")` may also be of interest. The ads package 575 | performs first- and second-order multi-scale analyses derived from 576 | Ripley's K-function. 577 | - The `r pkg("dbmss")` package allows 578 | simple computation of a full set of spatial statistic functions of 579 | distance, including classical ones (Ripley's K and others) and more 580 | recent ones used by spatial economists (Duranton and Overman's Kd, 581 | Marcon and Puech's M). It relies on `r pkg("spatstat")` for core calculation. 582 | 583 | ### Geostatistics 584 | 585 | Geostatistics uses a model fitted using the distances between observations to 586 | interpolate values observed at point to unobserved points 587 | 588 | - The `r pkg("gstat", priority = "core")` package provides a 589 | wide range of functions for univariate and multivariate geostatistics, 590 | also for larger datasets. 591 | - `r pkg("mbg")` offers an [interface](https://henryspatialanalysis.github.io/mbg/) 592 | for running model-based geostatistics with optional covariates and discrete spatial 593 | effects. 594 | - `r pkg("geoR", priority = "core")` contains 595 | functions for model-based geostatistics. 596 | - Variogram diagnostics may be 597 | carried out with `r pkg("vardiag")`. 598 | - Automated interpolation using `r pkg("gstat")` is available 599 | in `r pkg("automap")`. 600 | - This family of packages is supplemented by `r pkg("intamap")` with 601 | procedures for automated interpolation. 602 | - A similar wide range of functions is to be found in the 603 | `r pkg("fields")` package, extended by `r pkg("LatticeKrig")` 604 | for large spatial datasets and `r pkg("autoFRK")`. 605 | - The `r pkg("spatial")` package is shipped with base R, and 606 | contains several core geostatistical functions. 607 | - The `r pkg("spBayes")` package fits Gaussian univariate and 608 | multivariate models with MCMC. 609 | - `r pkg("ramps")` is a different Bayesian geostatistical 610 | modelling package. 611 | - The `r pkg("geospt")` package contains 612 | some geostatistical and radial basis functions, including prediction and 613 | cross validation. Besides, it includes functions for the design of 614 | optimal spatial sampling networks based on geostatistical modelling. 615 | - The `r pkg("FRK")` package is a tool for 616 | spatial/spatio-temporal modelling and prediction with large 617 | datasets. The approach, discussed in Cressie and Johannesson (2008), 618 | decomposes the field, and hence the covariance function, using a fixed 619 | set of n basis functions, where n is typically much smaller than the 620 | number of data points (or polygons) m. 621 | - `r pkg("SpatialExtremes")` proposes several 622 | approaches for spatial extremes. 623 | - In addition, `r pkg("constrainedKriging")` and `r pkg("geospt")` provide 624 | alternative approaches to geostatistical modelling. 625 | - The `r pkg("spTimer")` package is able to fit, spatially predict and 626 | temporally forecast large amounts of space-time data using \[1\] Bayesian 627 | Gaussian Process (GP) Models, \[2\] Bayesian Auto-Regressive (AR) Models, 628 | and \[3\] Bayesian Gaussian Predictive Processes (GPP) based AR Models. 629 | - The `r pkg("rtop")` package provides functions for the 630 | geostatistical interpolation of data with irregular spatial support such 631 | as runoff related data or data from administrative units. 632 | - The `r pkg("georob")` package provides functions for fitting 633 | linear models with spatially correlated errors by robust and Gaussian 634 | Restricted Maximum Likelihood and for computing robust and customary 635 | point and block kriging predictions, along with utility functions for 636 | cross-validation and for unbiased back-transformation of kriging 637 | predictions of log-transformed data. 638 | - The `r pkg("SpatialTools")` package has an emphasis on kriging, 639 | and provides functions for prediction and simulation. It is extended by 640 | `r pkg("ExceedanceTools")`, which provides tools for 641 | constructing confidence regions for exceedance regions and contour 642 | lines. 643 | - The `r pkg("gear")` package implements common 644 | geostatistical methods in a clean, straightforward, efficient manner, 645 | and is said to be a quasi reboot of `r pkg("SpatialTools")`. 646 | - The `r pkg("sperrorest")` package implements spatial error 647 | estimation and permutation-based spatial variable importance using 648 | different spatial cross-validation and spatial block bootstrap methods, used by 649 | `r pkg("mlr3spatiotempcv")`. 650 | - The `r pkg("sgeostat")` package is also available. Within 651 | the same general topical area are the 652 | `r pkg("deldir", priority = "core")` package for triangulation and the 653 | `r pkg("interp")` package for spline interpolation; the 654 | `r pkg("MBA")` package provides scattered data interpolation 655 | with multilevel B-splines. 656 | - In addition, there are the 657 | `r pkg("spatialCovariance")` package, which supports the 658 | computation of spatial covariance matrices for data on rectangles, the 659 | `r pkg("regress")` package building in part on 660 | `r pkg("spatialCovariance")`, and the 661 | `r pkg("tgp")` package. 662 | - The archived `Stem` 663 | package provided for the estimation of the parameters of a 664 | spatio-temporal model using the EM algorithm, and the estimation of the 665 | parameter standard errors using a spatio-temporal parametric bootstrap. 666 | - The `r pkg("SSN2")` is for geostatistical modeling 667 | for data on stream networks, including models based on in-stream 668 | distance. Models are created using moving average constructions. Spatial 669 | linear models, including covariates, can be fit with ML or REML. Mapping 670 | and other graphical functions are supported. 671 | - The `r pkg("ipdw")` provides functions to interpolate 672 | georeferenced point data via Inverse Path Distance Weighting. Useful 673 | for coastal marine applications where barriers in the landscape 674 | preclude interpolation with Euclidean distances. 675 | - `r pkg("sptotal")` uses Finite Population Block Kriging (FPBK) to 676 | provide a prediction for a quantity of interest, most commonly a 677 | population total or a prediction of total abundance, on a finite number 678 | of spatial sites. 679 | - `r pkg("spmodel")` fits statistical models to geostatistical 680 | and areal spatial data using a variety of covariance structures. 681 | Additional functionality allows for prediction (Kriging), non-spatial 682 | random effects, anisotropy, and big data. 683 | 684 | ### Disease mapping and areal data analysis 685 | 686 | Both point pattern analysis and geostatistics enter into disease mapping, which 687 | is concerned with representing public health information over space and 688 | time in a communicative and responsible way. Estimation is important to present 689 | calculated rates that are comparable both in terms of levels and uncertainty. 690 | 691 | - `r pkg("DCluster", priority = "core")` is a package for the 692 | detection of spatial clusters of diseases. It is complemented by 693 | `r pkg("DClusterm")` for model-based cluster detection, and by 694 | `r github("tkhrotn/rflexscan")` and `r pkg("FlexScan")`, two implementations 695 | of flexible scan statistics. 696 | - `r pkg("DCluster")` extends and depends on the 697 | `r pkg("spdep", priority = "core")` package, which provides 698 | basic functions for building neighbour lists and spatial weights. 699 | - `r pkg("spdep")` also provides global and local tests for spatial 700 | autocorrelation, including join-count tests, Moran's I, Geary's C, 701 | Getis-Ord G and others. 702 | - `r pkg("rgeoda")` is a wrapper for GeoDa and provides efficient alternatives 703 | for calculating global and local tests for spatial autocorrelation. 704 | - Some functions for fitting spatial regression models, such as SAR and CAR 705 | models are in `r pkg("spatialreg", priority = "core")`, see below. 706 | - The `r pkg("SpatialEpi")` package provides implementations of 707 | cluster detection and disease mapping functions, including Bayesian 708 | cluster detection, and supports strata. 709 | - The `r pkg("smerc")` package provides statistical methods 710 | for the analysis of data areal data, with a focus on cluster detection. 711 | - A Markov Random Field `"mrf"` effect may be added to models in the 712 | `r pkg("mgcv")` package shipped with base R, providing flexible 713 | modelling tools in a recommended package. 714 | - The `r pkg("hglm")` package also provides SAR and CAR model fitting 715 | approaches. 716 | - Regionalization of polygon objects 717 | is no longer provided by archived `AMOEBA`: a function to calculate 718 | spatial clusters using the Getis-Ord local statistic. It searched 719 | for irregular clusters (ecotopes) on a map. `skater()` in 720 | `r pkg("spdep")` does not interpose a local statistic, 721 | being based on distance between features in attribute space, 722 | and polygon contiguity. 723 | - The `r pkg("divseg")` and 724 | `r pkg("OasisR")` packages provide functions for measuring 725 | spatial segregation; `r pkg("OasisR")` includes Monte Carlo 726 | simulations to test the indices. 727 | - The `r pkg("lctools")` package provides 728 | researchers and educators with easy-to-learn user friendly tools for 729 | calculating key spatial statistics and to apply simple as well as 730 | advanced methods of spatial analysis in real data. These include: Local 731 | Pearson and Geographically Weighted Pearson Correlation Coefficients, 732 | Spatial Inequality Measures (Gini, Spatial Gini, LQ, Focal LQ), Spatial 733 | Autocorrelation (Global and Local Moran's I), several Geographically 734 | Weighted Regression techniques and other Spatial Analysis tools (other 735 | geographically weighted statistics). This package also contains 736 | functions for measuring the significance of each statistic calculated, 737 | mainly based on Monte Carlo simulations. The 738 | - `r pkg("sparr")` package provides another approach to 739 | relative risks. 740 | - The `r pkg("CARBayes")` package implements 741 | Bayesian hierarchical spatial areal unit models. In such models, the 742 | spatial correlation is modelled by a set of random effects, which are 743 | assigned a conditional autoregressive (CAR) prior distribution. Examples 744 | of the models included are the BYM model as well as a recently developed 745 | localised spatial smoothing model. 746 | - The `r pkg("spaMM")` 747 | package fits spatial GLMMs, using the Matern correlation function as the 748 | basic model for spatial random effects. 749 | - The `r pkg("PReMiuM")` package is for profile regression, which 750 | is a Dirichlet process Bayesian clustering model; it provides a spatial 751 | CAR term that can be included in the fixed effects (which are global, 752 | ie. non-cluster specific, parameters) to account for any spatial 753 | correlation in the residuals. 754 | - Spatial survival analysis is provided by the 755 | `r pkg("spBayesSurv")` package: Bayesian Modeling and 756 | Analysis of Spatially Correlated Survival Data. 757 | - The `r pkg("spselect")` package provides modelling functions 758 | based on forward stepwise regression, incremental forward stagewise 759 | regression, least angle regression (LARS), and lasso models for 760 | selecting the spatial scale of covariates in regression models. 761 | - Spatial microsimulation is offered by `r pkg("rakeR")`, `r pkg("sms")`, 762 | `r github("alexWhitworth/synthACS")` permits the building and 763 | running of spatially explicit agent-based models. 764 | - The `r pkg("geostan")` package has GLMs, SAR, proper CAR, ICAR, and eigenvector 765 | spatial filter (ESF) models for Bayesian disease mapping and spatial regression. 766 | The package uses the Stan modeling language for MCMC analysis. 767 | The package also contains exploratory spatial analysis tools (Moran scatter plot and 768 | various measures of spatial autocorrelation) and measurement error models 769 | designed for the use of (noisy) survey estimates as covariates. 770 | - `r pkg("waywiser")` helps assess models fit to spatial data, with 771 | functions for calculating the spatial autocorrelation of model 772 | residuals, for calculating model performance statistics, for 773 | assessing model performance across multiple spatial scales, and for 774 | calculating the "area of applicability" of a model. Functions are 775 | designed to be compatible with both base R and with the tidymodels 776 | modeling framework, and adopt `r pkg("yardstick")` classes and 777 | interfaces. 778 | - The `r pkg("gdverse")` package provides 779 | an integrated and extensible toolkit for analyzing spatial stratified heterogeneity 780 | and spatial associations using the geographical detector methodology. It includes 781 | core functions for computing the q-statistic, performing spatial factor exploration, 782 | and detecting spatial interactions between variables. The package supports various 783 | geographical detector models and provides high-performance implementations for their 784 | efficient execution. 785 | 786 | 787 | ### Spatial regression 788 | 789 | Many packages providing functions for fitting spatial regression models have 790 | already been given as they are used in disease mapping. In this subsection, 791 | more attention is given to the subset of methods used in spatial econometrics, and 792 | so complements general econometric methods covered in the `r view("Econometrics")` 793 | Task View. 794 | 795 | - The choice of function for spatial regression will depend on the support 796 | available. If the data are characterised by point support and the 797 | spatial process is continuous, geostatistical methods may be used, or 798 | functions in the `r pkg("nlme")` package. 799 | - If the support is 800 | areal, and the spatial process is not being treated as continuous, 801 | functions provided in the `r pkg("spatialreg")` package may 802 | be used. This package can also be seen as providing spatial econometrics 803 | functions. `r pkg("spdep")` provides the full range 804 | of local indicators of spatial association, such as local Moran's I and 805 | diagnostic tools for fitted linear models, including Lagrange Multiplier 806 | tests. Spatial regression models that can be fitted using maximum 807 | likelihood and Bayesian MCMC methods in 808 | `r pkg("spatialreg")` include spatial lag models, spatial 809 | error models, two parameter models, their Durbin variants and SLX models. 810 | For larger data sets, sparse 811 | matrix techniques can be used for maximum likelihood fits. In 812 | `r pkg("spatialreg")`, the `ME` and `SpatialFiltering` 813 | functions provide Moran Eigenvector model fitting, as do more modern 814 | functions in the `r pkg("spmoran")` package. 815 | - When using the generalized method of moments (GMM), `r pkg("sphet")` can be used 816 | to accommodate both autocorrelation and heteroskedasticity, also with 817 | instrumental variables. 818 | - The `r pkg("splm")` package provides methods for fitting spatial 819 | panel data by maximum likelihood and GM. 820 | - The `r pkg("spsur")` package provides functions to test and estimate 821 | spatial seemingly unrelated regression models (spatial SUR) by maximum 822 | likelihood and three-stage least squares. 823 | - The two small archived packages `S2sls` and `spanel` provide alternative 824 | implementations without most of the facilities of `r pkg("splm")`. 825 | - The former `HSAR` package provides Hierarchical 826 | Spatial Autoregressive Models (HSAR), based on a Bayesian Markov Chain 827 | Monte Carlo (MCMC) algorithm. 828 | - `r pkg("spatialprobit")` makes 829 | possible Bayesian estimation of the spatial autoregressive probit model 830 | (SAR probit model). 831 | - The `r pkg("ProbitSpatial")` package provides methods for 832 | fitting Binomial spatial probit models to larger data sets; spatial 833 | autoregressive (SAR) and spatial error (SEM) probit models are included. 834 | - The `r pkg("starma")` package provides functions to 835 | identify, estimate and diagnose a Space-Time AutoRegressive Moving 836 | Average (STARMA) model. 837 | - `r pkg("varycoef")` and `r pkg("spBayes")` provide implementations of 838 | spatially varying coefficient (SVC) models, which may be preferred to 839 | geographically weighted regression (GWR) models as having proper 840 | statistical foundations. 841 | - The `r pkg("gwrr")` package fits geographically weighted 842 | regression (GWR) models and has tools to diagnose and remediate 843 | collinearity in the GWR models. It also fits geographically weighted ridge 844 | regression (GWRR) and geographically weighted lasso (GWL) models. The 845 | `r pkg("GWmodel")` package contains functions for 846 | computing geographically weighted (GW) models. Specifically, basic, 847 | robust, local ridge, heteroskedastic, mixed, multiscale, generalised 848 | and space-time GWR; GW summary statistics, GW PCA and GW discriminant 849 | analysis; associated tests and diagnostics; and options for a range of 850 | distance metrics. 851 | - `r pkg("waywiser")` helps assess models fit to spatial data, with 852 | functions for calculating the spatial autocorrelation of model 853 | residuals, for calculating model performance statistics, for 854 | assessing model performance across multiple spatial scales, and for 855 | calculating the "area of applicability" of a model. Functions are 856 | designed to be compatible with both base R and with the tidymodels 857 | modeling framework, and adopt `r pkg("yardstick")` classes and 858 | interfaces. 859 | 860 | ### Ecological analysis 861 | 862 | There are many packages for analysing ecological and environmental data. 863 | They include: 864 | 865 | - `r pkg("ade4")` for exploratory and Euclidean methods in 866 | the environmental sciences, the adehabitat family of packages for 867 | the analysis of habitat selection by animals 868 | (`r pkg("adehabitatHR")`, 869 | `r pkg("adehabitatHS")`, 870 | `r pkg("adehabitatLT")`, and 871 | `r pkg("adehabitatMA")`) 872 | - `r pkg("pastecs")` for the regulation, decomposition and 873 | analysis of space-time series 874 | - `r pkg("vegan")` for ordination methods and other useful 875 | functions for community and vegetation ecologists, and many other 876 | functions in other contributed packages. One such is 877 | `r pkg("tripEstimation")`, basing on the classes 878 | provided by `r pkg("trip")`. 879 | - `r pkg("ncf")` provides a range of spatial 880 | nonparametric covariance functions. 881 | - The `r pkg("spind")` package provides functions for 882 | spatial methods based on generalized estimating equations (GEE) and 883 | wavelet-revised methods (WRM), functions for scaling by wavelet 884 | multiresolution regression (WMRR), conducting multi-model inference, 885 | and stepwise model selection. 886 | - The `r pkg("siplab")` package is a platform for 887 | experimenting with spatially explicit individual-based vegetation 888 | models. 889 | - `r pkg("ModelMap")` builds on other packages to create 890 | models using underlying GIS data. 891 | - The `r pkg("SpatialPosition")` computes spatial position 892 | models: Stewart potentials, Reilly catchment areas, Huff catchment 893 | areas. 894 | 895 | 896 | - The `r pkg("ngspatial")` package provides tools for 897 | analyzing spatial data, especially non-Gaussian areal data. It 898 | supports the sparse spatial generalized linear mixed model of Hughes 899 | and Haran (2013) and the centered autologistic model of Caragea and 900 | Kaiser (2009). 901 | - `r pkg("landscapemetrics")` package calculates landscape 902 | metrics for categorical landscape patterns. It can be used as a 903 | drop-in replacement for 904 | [FRAGSTATS](https://www.umass.edu/landeco/research/fragstats/fragstats.html), 905 | as it offers a reproducible workflow for landscape analysis in a 906 | single environment. It also provides several visualization 907 | functions, e.g. to show all labeled patches or the core area of all 908 | patches. 909 | - `r pkg("waywiser")` helps assess models fit to spatial data, with 910 | functions for calculating the spatial autocorrelation of model 911 | residuals, for calculating model performance statistics, for 912 | assessing model performance across multiple spatial scales, and for 913 | calculating the "area of applicability" of a model. Functions are 914 | designed to be compatible with both base R and with the tidymodels 915 | modeling framework, and adopt `r pkg("yardstick")` classes and 916 | interfaces. 917 | - `r pkg("dismo")` provides functions for species distribution modelling. 918 | 919 | The `r view("Environmetrics")` Task View contains a much more 920 | complete survey of relevant functions and packages. 921 | 922 | ### Machine learning of spatial data 923 | 924 | Machine learning of spatial data requires specialized methods to account for spatial dependencies like spatial autocorrelation -- where nearby observations tend to be similar. 925 | Ignoring these dependencies during model training and evaluation risks information leakage. 926 | For example, randomly splitting spatial data into training and testing subsets, without considering spatial autocorrelation, can result in test samples being spatially close to training samples. 927 | This violates the assumption of independence between training and test sets and can lead to inflated performance metrics and poor model generalization. 928 | 929 | To address this, various approaches and methods to account for spatial dependencies and relationships when building models were developed. 930 | In general, machine learning of spatial data can be performed through one of the existing machine learning frameworks in R, such as `r pkg("caret")`, `r pkg("mlr3")`, and `r pkg("tidymodels")` or through specialized spatial machine learning packages. 931 | 932 | - The `r pkg("caret")` package provides a consistent interface for training models but requires additional packages like `r pkg("blockCV")` or `r pkg("CAST")` to implement spatial methodologies. Functions like `CAST::knndm` and `CAST::ffs` enable spatially aware feature selection and cross-validation, while `CAST::aoa` assesses the area of applicability for spatial models. The `r pkg("mbg")` package offers convenience functions for fitting `r pkg("caret")` models with point-referenced outcomes and raster features. 933 | - `r pkg("mlr3")` with `r pkg("mlr3spatial")` and `r pkg("mlr3spatiotempcv")` takes an object-oriented approach with R6 classes for direct spatial object handling and cross-validation within its structured syntax. 934 | - `r pkg("tidymodels")` with `r pkg("spatialsample")` and `r pkg("waywiser")` introduces spatial sampling strategies and model evaluation tools following tidyverse principles, including `spatialsample::spatial_resample` and `waywiser::ww_area_of_applicability`. 935 | - `r pkg("RandomForestsGLS")` and `r pkg("spatialRF")` extend Random Forests to incorporate spatial dependence, offering specialized functions for spatial estimation, feature selection, and model assessment. 936 | - `r pkg("meteo")` implements Random Forest Spatial Interpolation by incorporating nearest observations and distances into the prediction process. 937 | - `r pkg("gpboost")` captures complex non-linear dependencies by combining gradient boosting with Gaussian processes. 938 | - `r pkg("sperrorest")` and `r pkg("blockCV")` provide frameworks for spatial resampling and validation, supporting methods like k-means clustering and block-based approaches to account for spatial dependencies in model evaluation. 939 | 940 | Installing packages linking to PROJ, GDAL or GEOS 941 | ------------------------------------------------- 942 | 943 | Installation of packages like `r pkg("gdalraster")`, `r pkg("sf")` and 944 | `r pkg("terra")` which use external software libraries such as PROJ, GDAL or 945 | GEOS requires care. For most users on platforms such as Windows or macOS who 946 | are not themselves package developers, it is always better to avoid what are 947 | known as source installs, because CRAN binary packages include all of the 948 | external software required. Because `getOption("pkgType")` on these platforms 949 | is usually `"both"`, you may be asked to choose to install a source package 950 | if it is more recent than the latest binary. 951 | 952 | Please do not be tempted to choose a source install for `r pkg("sf")` or 953 | `r pkg("terra")` or similar; the binary package will be generated within a 954 | day or two. To avoid being asked, you may see from `?options` 955 | under options provided by the utils package that the default 956 | behaviour of your installation of R may be controlled 957 | by setting options `install.packages.check.source` and 958 | `install.packages.compile.from.source`, or by setting environment variable 959 | `R_COMPILE_AND_INSTALL_PACKAGES`, see also this [helpful comment](https://github.com/r-spatial/sf/issues/1848#issuecomment-1005038753). 960 | 961 | If you are a developer using Windows or macOS or installing 962 | from `github`, the same static-linked 963 | binary external software libraries, header files, etc. as those used in 964 | building CRAN binary packages are available from: Windows 4.0 and 4.1 965 | [downloaded on-the-fly](https://github.com/orgs/rwinlib/repositories), 966 | Windows 4.2 [RTools42](https://cran.r-project.org/bin/windows/Rtools/rtools42/rtools.html), Windows 4.3 [RTools43](https://cran.r-project.org/bin/windows/Rtools/rtools43/rtools.html), 967 | and macOS [both architectures](https://mac.r-project.org/tools/). These 968 | external software libraries have been built using the same compile and 969 | link settings as R itself, so avoid the risk of possible errors caused by 970 | mismatched binaries. The current versions may be updated between R releases, in order to give access to more recent versions of GDAL, GEOS or PROJ. 971 | 972 | If you are a user (or developer) on systems where `getOption("pkgType")` 973 | is `"source"`, you will need to ensure that the external software is 974 | available when installing source packages. Advice for some such systems may 975 | be found [here](https://github.com/r-spatial/sf/#installing). 976 | [The most common reason](https://github.com/r-spatial/sf/#multiple-gdal-geos-andor-proj-versions-on-your-system) 977 | for failure is having multiple versions of external software installed 978 | on your platform. 979 | 980 | 981 | ### Links 982 | - [R-SIG-Geo mailing list](https://stat.ethz.ch/mailman/listinfo/R-SIG-Geo/) 983 | - [r-spatial](https://r-spatial.org/) 984 | - [rspatial](https://rspatial.org/) 985 | - [Geocomputation with R](https://geocompx.org/r.html) 986 | --------------------------------------------------------------------------------