CRAN Task View: Analysis of Spatial Data

Maintainer:Roger Bivand, Jakub Nowosad
Contact:Roger.Bivand at nhh.no, nowosad.jakub at gmail.com
Version:2022-08-31
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 (2022). CRAN Task View: Analysis of Spatial Data. Version 2022-08-31. 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 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 stackoverflow with appropriate tags, or of stackexchange. Using the #rspatial tag on twitter 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

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 (archived). 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 (archived) 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](../packages/rgdal/index.html) by the end of 2023 new projects should not use it, and existing projects should implement migration to the packages mentioned in the previous paragraph.

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

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:

Specific geospatial data sources of interest

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 forthcoming rtools42 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.

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, geoR, gstat, sf, spatialreg, spatstat, spdep, stars, terra.
Regular:ade4, adehabitatHR, adehabitatHS, adehabitatLT, adehabitatMA, ads, areal, autoFRK, automap, CARBayes, cartogram, chilemapas, cshapes, dbmss, DClusterm, divseg, ecespa, exactextractr, ExceedanceTools, fields, FlexScan, FRK, gdalcubes, gdalUtilities, gdistance, gear, geogrid, geojson, geojsonio, GEOmap, geomapdata, geometa, geonames, geonapi, geos, geosapi, geosphere, geospt, geouy, ggmap, ggplot2, ggsn, ggspatial, giscoR, gmt, GWmodel, gwrr, hglm, inlmisc, intamap, interp, ipdw, landsat, landscapemetrics, LatticeKrig, lctools, leaflet, libgeos, lidR, link2GI, lwgeom, magclass, mapdata, mapdeck, mapedit, mapmisc, mapproj, maps, mapsf, mapSpain, mapview, marmap, MBA, MBHdesign, mgcv, micromap, mlr3spatiotempcv, ModelMap, ncdf4, ncf, NetLogoR, ngspatial, nlme, OasisR, OpenStreetMap, osmdata, osmextract, ows4R, pastecs, PBSmapping, PBSmodelling, postGIStools, PReMiuM, ProbitSpatial, qualmap, rakeR, ramps, raster, rasterVis, rcartocolor, RColorBrewer, RCzechia, recmap, regress, rflexscan, rgbif, rgdal, rgee, rgeoda, RgoogleMaps, rgrass, rgrass7, rgugik, rLiDAR, rmapshaper, rnaturalearth, RNetCDF, rpostgis, RPostgreSQL, RPyGeo, RSAGA, Rsagacmd, rsample, RSurvey, rtop, s2, seg, sgeostat, shapefiles, siplab, smacpod, smerc, sms, sp, spacetime, spaMM, sparr, spatgraphs, spatial, spatialCovariance, SpatialEpi, SpatialExtremes, SpatialPosition, spatialprobit, spatialsample, SpatialTools, spBayes, spBayesSurv, Spbsampling, sperrorest, spgwr, sphet, spind, splancs, splm, spmoran, SpotSampling, spselect, spsur, spsurvey, spTimer, SSN, starma, statebins, synthACS, tgp, tidycensus, tigris, tmap, trip, tripEstimation, vardiag, vegan, viridis, Watersheds, wellknown, whitebox, wk, wkutils.
Archived:FieldSim, osmar, S2sls, spanel, vapour.

Related links

Other resources