CRAN Task View: Analysis of Spatial Data

Maintainer:Roger Bivand, Jakub Nowosad
Contact:Roger.Bivand at nhh.no, nowosad.jakub at gmail.com
Version:2024-11-15
URL:https://CRAN.R-project.org/view=Spatial
Source:https://github.com/cran-task-views/Spatial/
Contributions:Suggestions and improvements for this task view are very welcome and can be made through issues or pull requests on GitHub or via e-mail to the maintainer address. For further details see the Contributing guide.
Citation:Roger Bivand, Jakub Nowosad (2024). CRAN Task View: Analysis of Spatial Data. Version 2024-11-15. URL https://CRAN.R-project.org/view=Spatial.
Installation:The packages from this task view can be installed automatically using the ctv package. For example, ctv::install.views("Spatial", coreOnly = TRUE) installs all the core packages or ctv::update.views("Spatial") installs all packages that are not yet installed and up-to-date. See the CRAN Task View Initiative for more details.

Base R includes many functions that can be used for reading, visualising, and analysing spatial data. The focus in this view is on “geographical” spatial data, where observations can be identified with geographical locations, and where additional information about these locations may be retrieved if the location is recorded with care.

Base R functions are complemented by contributed packages provided as source packages, and as ready-to-run binary packages for Windows and macOS (Intel 64-bit and Apple Silicon arm64 architectures). Information about source installs of packages using software external to R may be found at the end of this page. This task view covers the current status of contributed packages available from CRAN.

The contributed packages address two broad areas: moving spatial data into and out of R including coordinate transformation, and analysing spatial data in R. Because the contributed packages constitute an evolving ecosystem, there are several points of entry for users looking for help and information. Two informal organisations curate websites: r-spatial with a hyphen, and rspatial without. R-spatial is more generally geo-informatics based, grew from the legacy sp package and is now clearly aligned with the modern sf and stars packages. Rspatial has grown from the raster package, now moving towards the modern terra package. It is also worth noting the wealth of online book projects, which may be helpful for users seeking an introduction, including Geocomputation with R.

Specific questions or issues may be raised where packageDescription(<pkg>)$BugReports returns an URL for bug reports or issues (where <pkg> is the name of the package as a string), or directly with package maintainers by email. Use may also be made of the R-SIG-Geo mailing-list after subscription, or of Stack Overflow with appropriate tags, or of Stack Exchange. Using the #rspatial tag on Twitter and Mastodon may also be worth trying, or browsing traffic using that tag (among others).

The packages in this view can be roughly structured into the following topics. If you think that some package is missing from the list, please e-mail the maintainer or submit an issue or pull request in the GitHub repository linked above.

Classes for spatial data and metadata

Many of the packages for handling and analysing spatial data use shared classes to reduce duplication of effort. Up until 2016, the sp package provided shared classes for spatial vector and raster data, but the representations used preceded more modern and efficient international standards for spatial vector data. From the release of sf, these modern vector representations are to be preferred. For spatial raster data, the representations proposed in stars and terra suit overlapping but slightly different requirements. Conversion between objects of classes defined by sf, stars, terra and the legacy sp packages are available, and are described in Conversions between different spatial classes in R.

Complementary initiatives are ongoing to support better handling of geographic metadata in R.

Spatial data - general

Raster data

Geographic metadata

Reading and writing spatial data

Spatial data is most often represented by one of two data models, vector or raster, and both models have many of their own file formats. GDAL (Geospatial Data Abstraction Library) is a (non-R) library that provides a unified way to read and write hundreds of spatial data formats. Formats supported by GDAL include both OGC standard data formats (e.g., GeoPackage) and proprietary formats (e.g., ESRI Shapefile). GDAL is used by a large number of GIS software and also many R packages, such as sf, terra, and vapour. This allows us to read and write spatial data in R from and to various spatial file formats. Important note: CRAN offers binary versions of packages sf, terra, and vapour for Windows and macOS, that contain specific GDAL version with a subset of possible data source drivers. If other drivers are needed, you need to either use other conversion utilities or install these packages from the source against a version of GDAL with the required drivers.

In the past, rgdal and raster (through rgdal) were recommended for reading and writing of spatial data in R. However, due to the retirement of rgdal on 16 October 2023 new projects should not use it, and existing projects should implement migration to the packages mentioned in the previous paragraph. In addition, rgeos and maptools were archived at the same time. Further details and links may be found in project reports on the evolution project. From October 2023, sp only uses methods from sf in place of those from rgdal for projection and access to the underlying definitions of coordinate reference systems.

Reading and writing spatial data - data formats

Other packages provide facilities to read and write spatial data, dealing with open standard formats or proprietary formats.

Open formats

Proprietary Data Formats

Reading and writing spatial data - GIS Software connectors

Specific geospatial data sources of interest

Interfaces to Spatial Web-Services

Some R packages focused on providing interfaces to web-services and web tools in support of spatial data management. Here follows a first tentative (non-exhaustive) list:

Remote sensing

Handling spatial data

Data processing - general

Data cleaning

Data processing - specific

Spatial sampling

Visualizing spatial data

Base visualization packages

Thematic cartography packages

Packages based on web-mapping frameworks

Building Cartograms

Analyzing spatial data

The division of spatial statistics into three partly overlapping areas: point pattern analysis, geostatistics and the analysis of areal/lattice data, is widely accepted. However, areal data analysis can be split into disease mapping and spatial regression (also partly overlapping). In addition, ecological analyses often approach spatial data in particular ways, giving rise to a specific topical cluster of packages. All of these approaches to analysing spatial data treat the spatial relationships between observations as a way of exploring and making use of important sources of information about the observations over and above what is known when assuming that they are independent of each other.

Point pattern analysis

Point pattern analysis examines the distance relationships between observed points, where the set of observations is expected to encompass all such entities in the study area.

Geostatistics

Geostatistics uses a model fitted using the distances between observations to interpolate values observed at point to unobserved points

Disease mapping and areal data analysis

Both point pattern analysis and geostatistics enter into disease mapping, which is concerned with representing public health information over space and time in a communicative and responsible way. Estimation is important to present calculated rates that are comparable both in terms of levels and uncertainty.

Spatial regression

Many packages providing functions for fitting spatial regression models have already been given as they are used in disease mapping. In this subsection, more attention is given to the subset of methods used in spatial econometrics, and so complements general econometric methods covered in the Econometrics Task View.

Ecological analysis

There are many packages for analysing ecological and environmental data. They include:

The Environmetrics Task View contains a much more complete survey of relevant functions and packages.

Installing packages linking to PROJ, GDAL or GEOS

Installation of packages like sf and terra which use external software libraries such as PROJ, GDAL or GEOS requires care. For most users on platforms such as Windows or macOS who are not themselves package developers, it is always better to avoid what are known as source installs, because CRAN binary packages include all of the external software required. Because getOption("pkgType") on these platforms is usually "both", you may be asked to choose to install a source package if it is more recent than the latest binary.

Please do not be tempted to choose a source install for sf or terra or similar; the binary package will be generated within a day or two. To avoid being asked, you may see from ?options under options provided by the utils package that the default behaviour of your installation of R may be controlled by setting options install.packages.check.source and install.packages.compile.from.source, or by setting environment variable R_COMPILE_AND_INSTALL_PACKAGES, see also this helpful comment.

If you are a developer using Windows or macOS or installing from github, the same static-linked binary external software libraries, header files, etc. as those used in building CRAN binary packages are available from: Windows 4.0 and 4.1 downloaded on-the-fly, Windows 4.2 RTools42, Windows 4.3 RTools43, and macOS both architectures. These external software libraries have been built using the same compile and link settings as R itself, so avoid the risk of possible errors caused by 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.

If you are a user (or developer) on systems where getOption("pkgType") is "source", you will need to ensure that the external software is available when installing source packages. Advice for some such systems may be found here. The most common reason for failure is having multiple versions of external software installed on your platform.

CRAN packages

Core:classInt, DCluster, deldir, dggridR, geoR, gstat, sf, spatialreg, spatstat, spdep, stars, terra.
Regular:ade4, adehabitatHR, adehabitatHS, adehabitatLT, adehabitatMA, ads, areal, autoFRK, automap, CARBayes, cartogram, CFtime, chilemapas, constrainedKriging, cshapes, dbmss, DClusterm, divseg, ecespa, elevatr, exactextractr, ExceedanceTools, fields, FlexScan, FRK, gdalcubes, gdalraster, gdalUtilities, gdistance, gear, geobr, geogrid, geojson, geojsonio, GEOmap, geomapdata, geometa, geonames, geonapi, georob, geos, geosapi, geosphere, geospt, geostan, geouy, ggmap, ggplot2, ggspatial, giscoR, gmt, GWmodel, gwrr, hglm, intamap, interp, ipdw, landsat, landscapemetrics, LatticeKrig, lctools, leaflet, libgeos, lidR, link2GI, lwgeom, magclass, mapdata, mapdeck, mapedit, mapme.biodiversity, mapmisc, mapproj, maps, mapsf, mapSpain, mapview, marmap, MBA, MBHdesign, mgcv, micromap, mlr3spatiotempcv, ModelMap, modisfast, MODISTools, ncdf4, ncf, ngspatial, nlme, OasisR, OpenStreetMap, osmapiR, osmdata, osmextract, ows4R, pastecs, PBSmapping, PBSmodelling, PReMiuM, ProbitSpatial, qgisprocess, qualmap, rakeR, ramps, raster, rasterVis, rcartocolor, RColorBrewer, RCzechia, recmap, regress, rflexscan, rgbif, rgee, RgoogleMaps, rgrass, rgugik, rmapshaper, rnaturalearth, RNetCDF, rpostgis, RPostgreSQL, RPyGeo, RSAGA, Rsagacmd, rsample, rsi, rstac, rtop, s2, sgeostat, shapefiles, siplab, sits, smacpod, smerc, sms, sp, spacetime, spaMM, sparr, spatgraphs, spaths, spatial, spatialCovariance, SpatialEpi, SpatialExtremes, SpatialPosition, spatialprobit, spatialsample, SpatialTools, spBayes, spBayesSurv, Spbsampling, sperrorest, sphet, spind, splancs, splm, spmodel, spmoran, spselect, spsur, spsurvey, spTimer, sptotal, SSN2, starma, statebins, synthACS, terrainr, tgp, tidycensus, tigris, tmap, trip, tripEstimation, vapour, vardiag, varycoef, vegan, viridis, waywiser, whitebox, wk, wkutils, yardstick.
Archived:rgeoda, seg, SpotSampling.

Related links

Other resources