## Getting spatial in R

The following pages will introduce some basic concepts of using the `R`

software for GIS operations. Nothing over the top but just a simple introduction to basic concepts like converting data to spatial objects, doing some spatial transformations, and data import and export of GIS data. `R`

continues to enhance its GIS functionality, so it is likely the number of sub pages will grow to try and illustrate these developments with digital soil science examples.

- Basic GIS operations with point data
- Basic GIS operations with raster data
- Raster resampling and reprojections
- Interactive mapping with
`leaflet`

- Raster clipping

### Notes on using `R`

for GIS stuff

`R`

is richly served with functionality to work with, analyse,
manipulate and map spatial data. Many procedures one would carry out in a GIS software, can more-or-less be scripted, automated and performed relatively easily in `R`

. The application of spatial data analysis in `R`

is well documented in Pebesma and Bivand (2023). There you will find a deep analysis with numerous examples of basic concepts right through to quite advanced analyses. Similarly Geocomputation with R is also a great resource with several relevant applications.

Naturally, in DSM, we constantly work with spatial data in one form or another e.g., points, polygons, rasters. We need to do such things as import, view, and export points to, in, and from a GIS. Similarly for polygons and rasters.

Many of the functions used for working with spatial data do not come with the base `R`

software. Thus we need to use specific functions from a range of different contributed `R`

packages. Probably the most important and most frequently used are:

`sf`

provides support for simple features, a standardized way to encode spatial vector data. Binds to`GDAL`

for reading and writing data, to`GEOS`

for geometrical operations, and to`PROJ`

for projection conversions and datum transformations.`terra`

provides methods for spatial data analysis with vector (points, lines, polygons) and raster (grid) data. Methods for vector data include geometric operations such as intersect and buffer. Raster methods include local, focal, global, zonal and geometric operations. The predict and interpolate methods facilitate the use of regression type (interpolation, machine learning) models for spatial prediction, including with satellite remote sensing data.

These 2 packages supercede previously fundamental packages like `sp`

, `raster`

, and `rgdal`

. While there several other `R`

libraries for helping with geospatial work, and many excellent resources available online (as indicated above) or in books, currently most GIS functionality needed for DSM can ably be done with with those packages mentioned above. However, note that applications involving more specialized GIS functionality, handling and manipulating spatial-temporal data, and working with data cubes for example, then perhaps packages like `stars`

are going to provide what you need. There will be examples in this course where other GIS relevant `R`

packages are used other than the main ones listed here, and will be introduced in due course.

## References

Pebesma, E.; Bivand, R. (2023). *Spatial Data Science: With Applications in R* (1st ed.). 314 pages. Chapman and Hall/CRC. https://doi.org/10.1201/9780429459016

Lovelace, R, J Nowosad, and J Muenchow. 2019. *Geocomputation with R*. Chapman & Hall/CRC The R Series.