Movatterモバイル変換
[0]ホーム
CRAN Task View: Analysis of Spatial Data
| Maintainer: | Roger Bivand, Jakub Nowosad, Krzysztof Dyba |
| Contact: | Roger.Bivand at nhh.no, nowosad.jakub at gmail.com, krzysztof.dyba at amu.edu.pl |
| Version: | 2025-11-11 |
| 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 theContributing guide. |
| Citation: | Roger Bivand, Jakub Nowosad, Krzysztof Dyba (2025). CRAN Task View: Analysis of Spatial Data. Version 2025-11-11. URL https://CRAN.R-project.org/view=Spatial. |
| Installation: | The packages from this task view can be installed automatically using thectv package. For example,ctv::install.views("Spatial", coreOnly = TRUE) installs all the core packages orctv::update.views("Spatial") installs all packages that are not yet installed and up-to-date. See theCRAN 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, andrspatial without. R-spatial is more generally geo-informatics based, grew from the legacysp package and is now clearly aligned with the modernsf andstars packages. Rspatial has grown from theraster package, now moving towards the modernterra package. It is also worth noting the wealth of online book projects, which may be helpful for users seeking an introduction, includingGeocomputation with R.
Specific questions or issues may be raised wherepackageDescription(<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 theR-SIG-Geo mailing-list after subscription, or ofStack Overflow with appropriate tags, or ofStack Exchange. Using the#rspatial tag onMastodon may also be worth trying, or browsing traffic using that tag (among others); BlueSky currently is emerging.
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.
Table of contents
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, thesp 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 ofsf, these modern vector representations are to be preferred. For spatial raster data, the representations proposed instars andterra suit overlapping but slightly different requirements. Conversion between objects of classes defined bysf,stars,terra and the legacysp packages are available, and are described inConversions between different spatial classes in R.
Complementary initiatives are ongoing to support better handling of geographic metadata in R.
Spatial data - general
- sf is a CRAN package for spatial vector data, providing Simple Features for R, in compliance with theOGC Simple Feature standard. The development of the package was supported by theR Consortium. It provides simple features access for vector data, and as such is a modern implementation and standardization of parts of the legacysp package.sf is documented in anR Journal article.sf uses thePROJ,GEOS andGDAL external software libraries, which must be available for source installs together with other external software libraries that they in turn depend on.
- stars is being actively developed and was initially supported by theR Consortium; it provides for spatiotemporal data in the form of dense arrays. It supercedes thespacetime package, which extended the shared classes defined insp for spatio-temporal data (seeSpatio-Temporal Data in R).stars uses PROJ and GDAL throughsf.
- terra provides classes for spatial vector and raster data, linking directly to PROJ, GDAL and GEOS. access to GDAL functionality for R packages.
- gdalraster provides API bindings to GDAL. Sincegdalraster 2.0.0, bindings are provided for both the Raster and VectorAPIs, the Geometry API (GEOS via GDAL headers) and Spatial Reference Systems API (PROJ via GDAL). Bindings are provided for the low-level Virtual Systems Interface (VSI) which abstracts file system operations and binary I/O on URLs, cloud storage services, compressed files (.zip, .gz, .tar, .tar.gz, .7z archives) and in-memory files, as well as regular file systems. When built against GDAL >= 3.11.3,gdalraster also provides bindings to GDAL’s unified command line interface framework, enablingthe use of CLI algorithms and pipeline processing from R.
- Thevapour package also offers low-level access to GDAL functionality for R packages.
- Thespatstat contains classes suited to the analysis of point patterns, and may be coerced to and from
"sf","stars" and other spatial classes.
Raster data
- terra is a re-implementation ofraster functionality and introducing new S4 classes for raster and vector data. See themanual and tutorials to get started.terra is very similar to theraster package; butterra is simpler and faster.
- stars provides for spatiotemporal data in the form of dense arrays, with space and time being array dimensions. Examples include socio-economic or demographic data, environmental variables monitored at fixed stations, time series of satellite images with multiple spectral bands, spatial simulations, and climate model results.
- Thegdalcubes package also provides classes for data cubes, including proxy data cubes, it links to PROJ, GDAL and NetCDF4.
- gdalraster provides an R implementation of theGDAL Raster Data Model, along with several utilities and algorithms for processing and analyzing raster data.
Geographic metadata
- geometa provides classes and methods to write geographic metadata following the ISO and OGC metadata standards (ISO 19115, 19110, 19119) and export it as XML (ISO 19139) for later publication into metadata catalogues. Reversely, geometa provides a way to read ISO 19139 metadata into R. The package extendssf to provide GML (ISO 19136) representation of geometries.
- ncdf4 provides read and write functions for handling metadata (CF conventions) in the self-described NetCDF format.
- CFtime encapsulates the CF time coordinate and allows to deal with the different CF calendars
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 assf,terra, andvapour, and thegdalraster package explicitly implements the GDALRaster andVector Data Models. 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 packagesgdalraster,sf,terra, andvapour 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 andraster (throughrgdal) were recommended for reading and writing of spatial data in R. However, due tothe 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 andmaptools were archived at the same time. Further details and links may be found inproject reports on the evolution project. From October 2023,sp only uses methods fromsf in place of those fromrgdal 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
- Well-Known Text (WKT) / Well-Known Binary (WKB): These standards are part of the OGC Simple Feature specification. Both WKT/WKB formats are supported by thesf package that implements the whole OGC Simple Feature specification in R. Additionally,wk may be used to parse well-known binary and well-known text representation of geometries to and from R-native formats.
- GeoJSON: An rOpenSciblog entry describes a GeoJSON-centred approach to reading GeoJSON and WKT data. The entry listsgeojson, andgeojsonio, among others. The GeoJSON format can also be read and written withgdalraster,sf,terra, andvapour.
- Geographic Markup Language (GML): GML format can be read and written withsf. Additional GML native reader and writer is provided bygeometa model with bindings to thesf classes, for extension of geographic metadata with GML data and metadata elements (GML 3.2.1 and 3.3) and interfacing OGC web-services inows4R package.
- NetCDF files: NetCDF files can be read and write withncdf4 orRNetCDF. Additionally, bothterra andstars have capabilities for reading and writing NetCDF files.
- LAS / LAX: These file formats are designed to work with lidar point cloud data and can be read/write withlidR.
Proprietary Data Formats
- ESRI formats: Many of spatial data saved into ESRI file formats can be read with GDAL, and thus also withsf,terra, andvapour. Additionally,shapefiles reads and writes ESRI ArcGIS/ArcView shapefiles. Additionally,maps (withmapdata andmapproj) provides a legacy tool to access to the same kinds of geographical databases as S.
- Others: Thegmt package gives a simple interface between GMT map-making software and R.
Reading and writing spatial data - GIS software connectors
- PostGIS: Therpostgis package provides additional functions to theRPostgreSQL package to interface R with a ‘PostGIS’-enabled database, as well as convenient wrappers to common ‘PostgreSQL’ queries. It is documented in anR Journal article.sf also provides an R interface to PostGIS, for both reading and writing, through GDAL.
- GRASS GIS: Integration with version 7.* and 8.* of the leading open source GIS, GRASS GIS, is provided in CRAN packagergrass, which usesterra for file transfer.
- SAGA GIS:RSAGA andRsagacmd offer shell-based wrapper for SAGA GIS commands.
- QGIS: QGIS version 2 was supported by RQGIS (RQGIS). Using QGIS processing algorithms is currently supported byqgisprocess, which uses the standalone ‘qgis_process’ command-line utility from QGIS (use recent QGIS versions; may work since >= 3.16). Both native QGIS and third-party (plugin) processing providers are supported, i.e. GRASS, SAGA, GDAL, …
- WhiteboxTools:whitebox is an R frontend for the WhiteboxTools software.
- ArcGIS:RPyGeo is a wrapper for Python access to the ArcGIS GeoProcessor. The ESRI company also offers their own package (r-bridge) that allows transferring data from ArcGIS to R.
- DuckDB:duckspatial is a package that allows and simplifies the process of writing and reading vector data into a DuckDB database through the SPATIAL extension.
- Various GIS Software, including Orfeo ToolBox and SAGA GIS, can also be connected to R usinglink2GI.
- Orfeo ToolBox segmentation module:OTBsegm simplifies the process of applying unsupervised segmentation algorithms available inOrfeo Toolbox via thelink2GI
Specific geospatial data sources of interest
- rnaturalearth package facilitates interaction withNatural Earth map data. It includes functions to download a wealth of Natural Earth vector and raster data, including cultural (e.g., country boundaries, airports, roads, railroads) and physical (e.g., coastline, lakes, glaciated areas) datasets.
- elevatr provides access to elevation data from several web services.
- Historical country boundaries (1886-today) can be obtained from thecshapes.
- marmap package is designed for downloading, plotting, and manipulating bathymetric and topographic data in R. It allows to query the ETOPO1 bathymetry and topography database hosted by the NOAA, use simple latitude-longitude-depth data in ASCII format, and take advantage of the advanced plotting tools available in R to build publication-quality bathymetric maps (see thePLOS paper).
- tidycensus provides access to US Census Bureau data in a tidy format, including the option to bind the data spatially on import.
- tigris provides access to cartographic elements provided by the US Census Bureau TIGER, including cartographic boundaries, roads, and water.
- rgbif package is used to access Global Biodiversity Information Facility (GBIF) occurrence data
- geonames is an interface to thewww.geonames.org service.
- osmdata is an R package for accessing relatively small datasets from OpenStreetMap (OSM), delivered via the Overpass API.osmextract matches, downloads, converts, and reads OpenStreetMap data covering large areas, obtained from Geofabrik and other providers.
- osmapiR is an R interface to theOpenStreetMap API for fetching and saving all kinds of data from/to the OpenStreetMap database, including map objects, GPS traces, notes, changesets, and users.
- OpenStreetMap gives access to open street map raster images.
- giscoR provides access to spatial elements provided by GISCO - Eurostat, including boundary files of countries, NUTS regions, municipalities, and other spatial objects.
- chilemapas provides access to spatial data of political and administrative divisions of Chile.
- geobr provided easy access to official spatial data sets of Brazil for multiple geographies and years.
- geouy(archived) loads and process geographic information for Uruguay.
- RCzechia downloads spatial boundary files of administrative regions and other spatial objects of the Czech Republic.
- rgugik allows to search and retrieve data from Polish Head Office of Geodesy and Cartography (“GUGiK”).
- mapSpain downloads spatial boundary files of administrative regions and other spatial objects of Spain.
- mapme.biodiversity allows to download and process a number open datasets related to biodiversity conservation providing efficient routines and parallelization options. Datasets include among others theGlobal Forest Watch,ESA/Copernicus Landcover,WorldClim andNASA FIRMS.
- terrainr provides an interface to theUnited States Geological Survey’s National Map services, providing elevation data and orthoimagery along other basemap tiles for the United States.
- geodata facilitates access to climate, elevation, soil, crop, species occurrence, and administrative boundary data, and is a successor of the
getData() function from theraster package. - forestdata(archived) allows to download forest and land cover data from various sources, includying forest inventory data, forest cover maps, and global canopy height models.
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:
- ows4R is a package that intends to provide an R interface to OGC standard Web-Services. It is in active development and currently support interfaces to the Web Feature Service (WFS) for vector data access, with binding to thesf package, and the Catalogue Service (CSW) for geographic metadata discovery and management (including transactions), with binding to thegeometa package.
- geosapi is an R client for theGeoServer REST API, an open source implementation used widely for serving spatial data.
- geonapi provides an interface to theGeoNetwork legacy API, an open source catalogue for managing geographic metadata.
Handling spatial data
Data cleaning
- sf has a built-in functions
st_is_valid to check whether a sf geometry is valid andst_make_valid to fix invalid geometry (from GEOS 3.8). - lwgeom may also be used to facilitate handling and reporting of topology errors and geometry validity issues in sf objects.
Data processing - general
- sf provides an interface to spatial geometry functions using theGEOS andS2 libraries; S2 is bundled in thes2 package whichsf methods use for topological predicates and operations on spherical or elliptical coordinates by default.
- stars contains tools for manipulating raster and vector data cubes.
- terra package introduces many GIS methods for spatial vector and raster data.
- ThegdalUtils (seehttps://stat.ethz.ch/pipermail/r-sig-geo/2022-April/028953.html) andgdalUtilities packages provide wrappers for the Geospatial Data Abstraction Library (GDAL) Utilities.
- gdalraster provides access to “traditional” GDAL utilities and algorithms via API bindings. When built against GDAL >= 3.11.3, bindings to GDAL’s unified CLI framework provide access to CLI algorithms and GDAL facilities for pipeline processing (seeUsing gdal CLI algorithms from R).
- Thegeos high-performance bindings to the GEOS library, based onlibgeos; the latter bundles a frozen copy of GEOS, and does not link to system versions, which may possibly be different versions of GEOS.
- rmapshaper is a wrapper around the ‘mapshaper’ ‘JavaScript’ library to perform topologically-aware polygon simplification and other operations such as clipping, erasing, dissolving, and converting ‘multi-part’ to ‘single-part’ geometries.
- gdistance andspaths provide functions to calculate distances and routes on geographic grids.
- geosphere permits computations of distance and area to be carried out on spatial data in geographical coordinates.
- dggridR provides a discrete global grid system via DGGRID. These grids are useful for spatial statistics because they tile the Earth withequally-sized hexagons, triangles, or diamonds.
- cshapes package provides functions for calculating distance matrices (seeMapping and Measuring Country Shapes).
- magclass offers a data class for increased interoperability working with spatial-temporal data together with corresponding functions and methods (conversions, basic calculations and basic data manipulation).
- Thetrip package extends spatial classes to permit the accessing and manipulating of spatial data for animal tracking.
Data processing - specific
- Theareal package can be used to interpolate overlapping but incongruent polygons, also known as areal weighted interpolation.
- Thecenterline package can be used for centerline (or median-axis) estimation of closed polygons, such as lakes, landslides, or rivers. The package also provides extensions toggplot2, allowing users to place
geom_text andgeom_label at the center of a spatial polygon, which can be useful for map-making. - Thequalmap package can be used to digitize qualitative GIS data.
- Theexactextractr for fast and accurate summary of raster values on polygonal areas (known as zonal statistics).
Remote sensing
- rstac provides functions to access, search and download spacetime earth observation data viaSpatioTemporal Asset Catalogs. This package supports the version 1.0.0 (and older) of theSTAC specification.
- Thersi package provides an interface to theAwesome Spectral Indices project. It also provides functions to download, mask, and composite data fromSpatioTemporal Asset Catalogs, with a particular focus on satellite imagery.
- TheRStoolbox is a remote sensing toolbox covering many aspects including data import, pre-processing, data analysis, image classification and graphical display.
- Thesits is an end-to-end toolkit for land use and land cover classification using big Earth observation data, based on machine learning methods applied to satellite image data cubes.
- Thelandsat package with accompanyingJSS paper provides tools for exploring and developing correction tools for remote sensing data.
- luna has tools for acquiring and processing satellite remote sensing data from NASA’s LANDSAT and MODIS data sources.MODISTools also provides an interface to theMODIS Land Products Subsets web services.modisfast, on its side, provides an interface to some MODIS, VIIRS and GPMOPeNDAP servers, enabling to subset the datacubes directly at the download phase.
- TheCDSE provides the interface to the ‘Copernicus Data Space Ecosystem’ API (https://dataspace.copernicus.eu/analyse/apis/sentinel-hub), mainly for searching the catalogue of available data from Copernicus Sentinel missions and obtaining the images for the area of interest based on selected spectral bands.
- Thersat is designed for automatically downloading, pre-processing, and managing time series of satellite imagery from multiple platforms (i.e., Landsat, Sentinel and MODIS).
- rgee is anEarth Engine client library for R. All of the ‘Earth Engine’ API classes, modules, and functions are made available. Additional functions implemented include importing (exporting) of Earth Engine spatial objects, extraction of time series, interactive map display, assets management interface, and metadata display.
- Theopeneo is an R client package that allows users to interact with openEO-compliant back-ends (https://openeo.org/) for processing Earth observation data (e.g., services offered by European Space Agency or VITO Remote Sensing). It enables to define and execute workflows remotely on cloud infrastructures without having to download large amounts of data locally.
Spatial sampling
- spsurvey provides functions to select generalized random-tessellation stratified (GRTS) probability samples and analyze survey data.
- Spbsampling allows selecting probability samples well spread over the population of interest, in any dimension and using any distance function.
- spatialsample is a member of the tidymodels family of packages and contains functions and classes for spatial resampling to use withrsample.
- MBHdesign provides spatially survey balanced designs using the quasi-random number method.
Visualizing spatial data
Base visualization packages
- Packages such assf,stars,terra, andrasterVis provide basic visualization methods through the generic plot function.
- classInt package provides functions for choosing class intervals for thematic cartography.
- Currently, the grDevices package (included with the R installation) contains a large number of color palettes that can be accessed with the
hcl.colors andpalette.colors functions; see also New features in thisblog. Some of these color palettes can be also retrieved using separate packages, such asRColorBrewer,viridis, orrcartocolor.
Thematic cartography packages
- tmap package accepts most spatial data classes and provides a modern basis for thematic mapping using a Grammar of Graphics syntax. It also allows for interactive spatial data mapping.
- mapsf package allows various cartographic representations such as proportional symbols, choropleth, or typology maps; it accepts sf (sf) and SpatRaster (terra) objects
- ggplot2 package has a built-in support for sf objects with the
geom_sf function and additional support for stars object is available through thegeom_stars function available in thestars package. Its spatial visualization capabilities can be further extended withggspatial, which adds support for more spatial classes (including classes from the raster package), allows adding north arrows and scale bars, etc. - Themapmisc package is a minimal, light-weight set of tools for producing nice-looking maps in R, with support for map projections.
- Additional processing and mapping functions are available inPBSmapping package;PBSmodelling provides modelling support. In addition,GEOmap provides mapping facilities directed to meet the needs of geologists and uses thegeomapdata package.
Packages based on web-mapping frameworks
- mapview andleaflet packages provide methods to view spatial objects interactively, usually on a web mapping base. Additionally,tmap has a view mode that allows for interactive spatial data mapping.
- mapdeck package provides a mechanism to plot interactive maps through javascript libraries ‘Mapbox GL’ and ‘Deck.gl’.
- RgoogleMaps package for accessing Google Maps(TM) may be useful if the user wishes to place a map backdrop behind other displays.
- ggmap may be used for spatial visualization with Google Maps and OpenStreetMap.
- mapedit provides an R shiny widget based onleaflet for editing or creating sf geometries.
Building cartograms
- cartogram package allows for constructions of a continuous area cartogram by a rubber sheet distortion algorithm, non-contiguous area cartograms, and non-overlapping circles cartogram.
- geogrid package turns polygons into rectangular or hexagonal cartograms.
- micromap package provides linked micromaps using ggplot2.
- recmap package provides rectangular cartograms with rectangle sizes reflecting for example population.
- geogrid turns spatial polygons into regular or hexagonal grids.statebins provides a simple binning approach to US states.
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. Moreover, machine learning for spatial data is a growing area of interest, and there are packages that provide tools for this. 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.
- spatstat is a family of R packages for analysing spatial point pattern data (and other kinds of spatial data). It has extensive capabilities for exploratory analysis, statistical modelling, simulation and statistical inference. It allows freedom in defining the region(s) of interest, and makes extensions to marked processes and spatial covariates. Its strengths are model-fitting and simulation, and it has a usefulhomepage; it isactively developed. It is the only package that will enable the user to fit inhomogeneous point process models with interpoint interactions.
- Thesplancs package allows point data to be analysed within a polygonal region of interest, and covers many methods, including 2D kernel densities.
- Thespatial package is a recommended package shipped with base R, and contains several core functions, including an implementation of Khat by its author, Prof. Ripley.
- Thespatgraphs package provides graphs, graph visualisation and graph based summaries to be used with spatial point pattern analysis.
- Thesmacpod package provides various statistical methods for analyzing case-control point data. The methods available closely follow those in chapter 6 of Applied Spatial Statistics for Public Health Data by Waller and Gotway (2004).
- ecespa provides wrappers, functions and data for spatial point pattern analysis, used in the book on Spatial Ecology of the ECESPA/AEET. The functions for binning points on grids in
- ads may also be of interest. The ads package performs first- and second-order multi-scale analyses derived from Ripley’s K-function.
- Thedbmss package allows simple computation of a full set of spatial statistic functions of distance, including classical ones (Ripley’s K and others) and more recent ones used by spatial economists (Duranton and Overman’s Kd, Marcon and Puech’s M). It relies onspatstat for core calculation.
- sfhotspot provides functions for descriptive hotspot analysis and mapping of spatial concentrations of points, including kernel-density estimation, Getis–Ord Gi*, hotspot classification, etc. The package attempts to provide sensible default values to assist with analysis and mapping for students and non-experts.
Geostatistics
Geostatistics uses a model fitted using the distances between observations to interpolate values observed at point to unobserved points
- Thegstat package provides a wide range of functions for univariate and multivariate geostatistics, also for larger datasets.
- mbg offers aninterface for running model-based geostatistics with optional covariates and discrete spatial effects.
- geoR contains functions for model-based geostatistics.
- Variogram diagnostics may be carried out withvardiag.
- Automated interpolation usinggstat is available inautomap.
- This family of packages is supplemented byintamap with procedures for automated interpolation.
- A similar wide range of functions is to be found in thefields package, extended byLatticeKrig for large spatial datasets andautoFRK.
- Thespatial package is shipped with base R, and contains several core geostatistical functions.
- ThespBayes package fits Gaussian univariate and multivariate models with MCMC.
- ramps is a different Bayesian geostatistical modelling package.
- Thegeospt package contains some geostatistical and radial basis functions, including prediction and cross validation. Besides, it includes functions for the design of optimal spatial sampling networks based on geostatistical modelling.
- TheFRK package is a tool for spatial/spatio-temporal modelling and prediction with large datasets. The approach, discussed in Cressie and Johannesson (2008), decomposes the field, and hence the covariance function, using a fixed set of n basis functions, where n is typically much smaller than the number of data points (or polygons) m.
- SpatialExtremes proposes several approaches for spatial extremes.
- In addition,constrainedKriging andgeospt provide alternative approaches to geostatistical modelling.
- ThespTimer package is able to fit, spatially predict and temporally forecast large amounts of space-time data using [1] Bayesian Gaussian Process (GP) Models, [2] Bayesian Auto-Regressive (AR) Models, and [3] Bayesian Gaussian Predictive Processes (GPP) based AR Models.
- Thertop package provides functions for the geostatistical interpolation of data with irregular spatial support such as runoff related data or data from administrative units.
- Thegeorob package provides functions for fitting linear models with spatially correlated errors by robust and Gaussian Restricted Maximum Likelihood and for computing robust and customary point and block kriging predictions, along with utility functions for cross-validation and for unbiased back-transformation of kriging predictions of log-transformed data.
- TheSpatialTools package has an emphasis on kriging, and provides functions for prediction and simulation. It is extended byExceedanceTools, which provides tools for constructing confidence regions for exceedance regions and contour lines.
- Thegear package implements common geostatistical methods in a clean, straightforward, efficient manner, and is said to be a quasi reboot ofSpatialTools.
- Thesperrorest package implements spatial error estimation and permutation-based spatial variable importance using different spatial cross-validation and spatial block bootstrap methods, used bymlr3spatiotempcv.
- Thesgeostat package is also available. Within the same general topical area are thedeldir package for triangulation and theinterp package for spline interpolation; theMBA package provides scattered data interpolation with multilevel B-splines.
- In addition, there are thespatialCovariance package, which supports the computation of spatial covariance matrices for data on rectangles, theregress package building in part onspatialCovariance, and thetgp package.
- The archived
Stem package provided for the estimation of the parameters of a spatio-temporal model using the EM algorithm, and the estimation of the parameter standard errors using a spatio-temporal parametric bootstrap. - TheSSN2 is for geostatistical modeling for data on stream networks, including models based on in-stream distance. Models are created using moving average constructions. Spatial linear models, including covariates, can be fit with ML or REML. Mapping and other graphical functions are supported.
- Theipdw provides functions to interpolate georeferenced point data via Inverse Path Distance Weighting. Useful for coastal marine applications where barriers in the landscape preclude interpolation with Euclidean distances.
- sptotal uses Finite Population Block Kriging (FPBK) to provide a prediction for a quantity of interest, most commonly a population total or a prediction of total abundance, on a finite number of spatial sites.
- spmodel fits statistical models to geostatistical and areal spatial data using a variety of covariance structures. Additional functionality allows for prediction (Kriging), non-spatial random effects, anisotropy, and big data.
- spStack uses predictive stacking to fit Bayesian spatial and spatial-temporal models for point-referenced Gaussian, Poisson, binomial, and binary data without using MCMC.
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.
- DCluster is a package for the detection of spatial clusters of diseases. It is complemented byDClusterm for model-based cluster detection, and byrflexscan andFlexScan, two implementations of flexible scan statistics.
- DCluster extends and depends on thespdep package, which provides basic functions for building neighbour lists and spatial weights.
- spdep also provides global and local tests for spatial autocorrelation, including join-count tests, Moran’s I, Geary’s C, Getis-Ord G and others.
- rgeoda is a wrapper for GeoDa and provides efficient alternatives for calculating global and local tests for spatial autocorrelation.
- Some functions for fitting spatial regression models, such as SAR and CAR models are inspatialreg, see below.
- TheSpatialEpi package provides implementations of cluster detection and disease mapping functions, including Bayesian cluster detection, and supports strata.
- Thesmerc package provides statistical methods for the analysis of data areal data, with a focus on cluster detection.
- A Markov Random Field
"mrf" effect may be added to models in themgcv package shipped with base R, providing flexible modelling tools in a recommended package. - Thehglm package also provides SAR and CAR model fitting approaches.
- Regionalization of polygon objects is no longer provided by archived
AMOEBA: a function to calculate spatial clusters using the Getis-Ord local statistic. It searched for irregular clusters (ecotopes) on a map.skater() inspdep does not interpose a local statistic, being based on distance between features in attribute space, and polygon contiguity. - Thedivseg andOasisR packages provide functions for measuring spatial segregation;OasisR includes Monte Carlo simulations to test the indices.
- Thelctools(archived) package provides researchers and educators with easy-to-learn user friendly tools for calculating key spatial statistics and to apply simple as well as advanced methods of spatial analysis in real data. These include: Local Pearson and Geographically Weighted Pearson Correlation Coefficients, Spatial Inequality Measures (Gini, Spatial Gini, LQ, Focal LQ), Spatial Autocorrelation (Global and Local Moran’s I), several Geographically Weighted Regression techniques and other Spatial Analysis tools (other geographically weighted statistics). This package also contains functions for measuring the significance of each statistic calculated, mainly based on Monte Carlo simulations. The
- sparr package provides another approach to relative risks.
- TheCARBayes package implements Bayesian hierarchical spatial areal unit models. In such models, the spatial correlation is modelled by a set of random effects, which are assigned a conditional autoregressive (CAR) prior distribution. Examples of the models included are the BYM model as well as a recently developed localised spatial smoothing model.
- ThespaMM package fits spatial GLMMs, using the Matern correlation function as the basic model for spatial random effects.
- ThePReMiuM package is for profile regression, which is a Dirichlet process Bayesian clustering model; it provides a spatial CAR term that can be included in the fixed effects (which are global, ie. non-cluster specific, parameters) to account for any spatial correlation in the residuals.
- Spatial survival analysis is provided by thespBayesSurv package: Bayesian Modeling and Analysis of Spatially Correlated Survival Data.
- Thespselect package provides modelling functions based on forward stepwise regression, incremental forward stagewise regression, least angle regression (LARS), and lasso models for selecting the spatial scale of covariates in regression models.
- Spatial microsimulation is offered byrakeR,sms,synthACS permits the building and running of spatially explicit agent-based models.
- Thegeostan package has GLMs, SAR, proper CAR, ICAR, and eigenvector spatial filter (ESF) models for Bayesian disease mapping and spatial regression. The package uses the Stan modeling language for MCMC analysis. The package also contains exploratory spatial analysis tools (Moran scatter plot and various measures of spatial autocorrelation) and measurement error models designed for the use of (noisy) survey estimates as covariates.
- waywiser helps assess models fit to spatial data, with functions for calculating the spatial autocorrelation of model residuals, for calculating model performance statistics, for assessing model performance across multiple spatial scales, and for calculating the “area of applicability” of a model. Functions are designed to be compatible with both base R and with the tidymodels modeling framework, and adoptyardstick classes and interfaces.
- Thegdverse package provides an integrated and extensible toolkit for analyzing spatial stratified heterogeneity and spatial associations using the geographical detector methodology. It includes core functions for computing the q-statistic, performing spatial factor exploration, and detecting spatial interactions between variables. The package supports various geographical detector models and provides high-performance implementations for their efficient execution.
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 theEconometrics Task View.
- The choice of function for spatial regression will depend on the support available. If the data are characterised by point support and the spatial process is continuous, geostatistical methods may be used, or functions in thenlme package.
- If the support is areal, and the spatial process is not being treated as continuous, functions provided in thespatialreg package may be used. This package can also be seen as providing spatial econometrics functions.spdep provides the full range of local indicators of spatial association, such as local Moran’s I and diagnostic tools for fitted linear models, including Lagrange Multiplier tests. Spatial regression models that can be fitted using maximum likelihood and Bayesian MCMC methods inspatialreg include spatial lag models, spatial error models, two parameter models, their Durbin variants and SLX models. For larger data sets, sparse matrix techniques can be used for maximum likelihood fits. Inspatialreg, the
ME andSpatialFiltering functions provide Moran Eigenvector model fitting, as do more modern functions in thespmoran package. - When using the generalized method of moments (GMM),sphet can be used to accommodate both autocorrelation and heteroskedasticity, also with instrumental variables.
- Thesplm package provides methods for fitting spatial panel data by maximum likelihood and GM.
- Thespsur package provides functions to test and estimate spatial seemingly unrelated regression models (spatial SUR) by maximum likelihood and three-stage least squares.
- The two small archived packages
S2sls andspanel provide alternative implementations without most of the facilities ofsplm. - The former
HSAR package provides Hierarchical Spatial Autoregressive Models (HSAR), based on a Bayesian Markov Chain Monte Carlo (MCMC) algorithm. - spatialprobit makes possible Bayesian estimation of the spatial autoregressive probit model (SAR probit model).
- TheProbitSpatial package provides methods for fitting Binomial spatial probit models to larger data sets; spatial autoregressive (SAR) and spatial error (SEM) probit models are included.
- Thestarma package provides functions to identify, estimate and diagnose a Space-Time AutoRegressive Moving Average (STARMA) model.
- varycoef andspBayes provide implementations of spatially varying coefficient (SVC) models, which may be preferred to geographically weighted regression (GWR) models as having proper statistical foundations.
- Thegwrr package fits geographically weighted regression (GWR) models and has tools to diagnose and remediate collinearity in the GWR models. It also fits geographically weighted ridge regression (GWRR) and geographically weighted lasso (GWL) models. TheGWmodel package contains functions for computing geographically weighted (GW) models. Specifically, basic, robust, local ridge, heteroskedastic, mixed, multiscale, generalised and space-time GWR; GW summary statistics, GW PCA and GW discriminant analysis; associated tests and diagnostics; and options for a range of distance metrics.
- waywiser helps assess models fit to spatial data, with functions for calculating the spatial autocorrelation of model residuals, for calculating model performance statistics, for assessing model performance across multiple spatial scales, and for calculating the “area of applicability” of a model. Functions are designed to be compatible with both base R and with the tidymodels modeling framework, and adoptyardstick classes and interfaces.
- spStack fits Bayesian spatially-temporally varying coefficients (STVC) generalized linear models without MCMC using stacking of predictive densities.
Ecological analysis
There are many packages for analysing ecological and environmental data. They include:
- ade4 for exploratory and Euclidean methods in the environmental sciences, the adehabitat family of packages for the analysis of habitat selection by animals (adehabitatHR,adehabitatHS,adehabitatLT, andadehabitatMA)
- pastecs for the regulation, decomposition and analysis of space-time series
- vegan for ordination methods and other useful functions for community and vegetation ecologists, and many other functions in other contributed packages. One such istripEstimation, basing on the classes provided bytrip.
- ncf provides a range of spatial nonparametric covariance functions.
- Thespind package provides functions for spatial methods based on generalized estimating equations (GEE) and wavelet-revised methods (WRM), functions for scaling by wavelet multiresolution regression (WMRR), conducting multi-model inference, and stepwise model selection.
- Thesiplab package is a platform for experimenting with spatially explicit individual-based vegetation models.
- ModelMap builds on other packages to create models using underlying GIS data.
- TheSpatialPosition computes spatial position models: Stewart potentials, Reilly catchment areas, Huff catchment areas.
- Thengspatial package provides tools for analyzing spatial data, especially non-Gaussian areal data. It supports the sparse spatial generalized linear mixed model of Hughes and Haran (2013) and the centered autologistic model of Caragea and Kaiser (2009).
- landscapemetrics package calculates landscape metrics for categorical landscape patterns. It can be used as a drop-in replacement forFRAGSTATS, as it offers a reproducible workflow for landscape analysis in a single environment. It also provides several visualization functions, e.g. to show all labeled patches or the core area of all patches.
- waywiser helps assess models fit to spatial data, with functions for calculating the spatial autocorrelation of model residuals, for calculating model performance statistics, for assessing model performance across multiple spatial scales, and for calculating the “area of applicability” of a model. Functions are designed to be compatible with both base R and with the tidymodels modeling framework, and adoptyardstick classes and interfaces.
- dismo provides functions for species distribution modelling.
TheEnvironmetrics Task View contains a much more complete survey of relevant functions and packages.
Machine learning of spatial data
Machine learning of spatial data requires specialized methods to account for spatial dependencies like spatial autocorrelation – where nearby observations tend to be similar. Ignoring these dependencies during model training and evaluation risks information leakage. 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. This violates the assumption of independence between training and test sets and can lead to inflated performance metrics and poor model generalization.
To address this, various approaches and methods to account for spatial dependencies and relationships when building models were developed. In general, machine learning of spatial data can be performed through one of the existing machine learning frameworks in R, such ascaret,mlr3, andtidymodels or through specialized spatial machine learning packages.
- Thecaret package provides a consistent interface for training models but requires additional packages likeblockCV orCAST to implement spatial methodologies. Functions like
CAST::knndm andCAST::ffs enable spatially aware feature selection and cross-validation, whileCAST::aoa assesses the area of applicability for spatial models. Thembg package offers convenience functions for fittingcaret models with point-referenced outcomes and raster features. - mlr3 withmlr3spatial andmlr3spatiotempcv takes an object-oriented approach with R6 classes for direct spatial object handling and cross-validation within its structured syntax.
- tidymodels withspatialsample andwaywiser introduces spatial sampling strategies and model evaluation tools following tidyverse principles, including
spatialsample::spatial_resample andwaywiser::ww_area_of_applicability. - RandomForestsGLS andspatialRF extend Random Forests to incorporate spatial dependence, offering specialized functions for spatial estimation, feature selection, and model assessment.
- meteo implements Random Forest Spatial Interpolation by incorporating nearest observations and distances into the prediction process.
- gpboost captures complex non-linear dependencies by combining gradient boosting with Gaussian processes.
- sperrorest andblockCV 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.
Installing packages linking to PROJ, GDAL or GEOS
Installation of packages likegdalraster,sf andterra 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. BecausegetOption("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 forsf orterra 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 optionsinstall.packages.check.source andinstall.packages.compile.from.source, or by setting environment variableR_COMPILE_AND_INSTALL_PACKAGES, see also thishelpful comment.
If you are a developer using Windows or macOS or installing fromgithub, 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.1downloaded on-the-fly, Windows 4.2RTools42, Windows 4.3RTools43, and macOSboth 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 wheregetOption("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 foundhere.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,blockCV,CARBayes,caret,cartogram,CAST,CDSE,centerline,CFtime,chilemapas,constrainedKriging,cshapes,dbmss,DClusterm,dismo,divseg,duckspatial,ecespa,elevatr,exactextractr,ExceedanceTools,fields,FlexScan,FRK,gdalcubes,gdalraster,gdalUtilities,gdistance,gdverse,gear,geobr,geodata,geogrid,geojson,geojsonio,GEOmap,geomapdata,geometa,geonames,geonapi,georob,geos,geosapi,geosphere,geospt,geostan,ggmap,ggplot2,ggspatial,giscoR,gmt,gpboost,GWmodel,gwrr,hglm,intamap,interp,ipdw,landsat,landscapemetrics,LatticeKrig,leaflet,libgeos,lidR,link2GI,lwgeom,magclass,mapdata,mapdeck,mapedit,mapme.biodiversity,mapmisc,mapproj,maps,mapsf,mapSpain,mapview,marmap,MBA,mbg,MBHdesign,meteo,mgcv,micromap,mlr3,mlr3spatial,mlr3spatiotempcv,ModelMap,modisfast,MODISTools,ncdf4,ncf,ngspatial,nlme,OasisR,openeo,OpenStreetMap,osmapiR,osmdata,osmextract,OTBsegm,ows4R,pastecs,PBSmapping,PBSmodelling,PReMiuM,ProbitSpatial,qgisprocess,qualmap,rakeR,ramps,RandomForestsGLS,raster,rasterVis,rcartocolor,RColorBrewer,RCzechia,recmap,regress,rgbif,rgee,rgeoda,RgoogleMaps,rgrass,rgugik,rmapshaper,rnaturalearth,RNetCDF,rpostgis,RPostgreSQL,RPyGeo,RSAGA,Rsagacmd,rsample,rsat,rsi,rstac,RStoolbox,rtop,s2,sfhotspot,sgeostat,shapefiles,siplab,sits,smacpod,smerc,sms,sp,spacetime,spaMM,sparr,spatgraphs,spaths,spatial,spatialCovariance,SpatialEpi,SpatialExtremes,SpatialPosition,spatialprobit,spatialRF,spatialsample,SpatialTools,spBayes,spBayesSurv,Spbsampling,sperrorest,sphet,spind,splancs,splm,spmodel,spmoran,spselect,spStack,spsur,spsurvey,spTimer,sptotal,SSN2,starma,statebins,terrainr,tgp,tidycensus,tidymodels,tigris,tmap,trip,tripEstimation,vapour,vardiag,varycoef,vegan,viridis,waywiser,whitebox,wk,yardstick. |
| Archived: | forestdata,geouy,lctools. |
Related links
Other resources
[8]ページ先頭