If the coordinates of just one cell (usually called the origin) are known, then the coordinates of any other cell can be determined automatically based on its relative position in the grid. Because raster cells are all the same size and arranged on a regular grid, it is not necessary to record the x and y coordinates of every cell. In most situations, data frames are very inefficient for storing raster data. Fortunately, raster objects can be converted to data frames with one row per cell, columns for the x and y coordinates, and columns for one or more attribute that are associated with each cell. However, ggplot() only works with inputs in the form of a data frame and therefore cannot be used to directly map a SpatRaster object. The ggplot() function can be used to make maps with raster data, as well as vector data. However, terra is by far the most flexible and powerful package currently available in R for handling raster data. For example, the older sp package supports the SpatialGridDataFrame class for gridded datasets and spatstat supports the im class for pixel image objects. There are several other packages that can handle raster data. To avoid unnecessary confusion, the code in this book is based entirely on the newer terra package. However, the terra package contains several major improvements, including faster processing speed for large rasters. The data objects and the function syntax in the two packages are very similar, and longtime raster users should find it straightforward to work with terra. It is intended to replace the raster package, which has been the main raster data package in R for many years. The terra package provides a variety of specialized classes and functions for importing, processing, analyzing, and visualizing raster datasets ( Hijmans 2022). However, the raster format can be imprecise and inefficient for point, line, and small polygon features such as plot locations, roads, streams, and water bodies. Continuous variables such as elevation, temperature, and precipitation as well as categorical data such as discrete vegetation types and land cover classes can often be stored and manipulated more efficiently as rasters. The raster data format has several advantages and limitations compared to vector data. The spatial characteristics of a raster dataset are defined by its spatial resolution (the height and width of each cell) and its origin (typically the upper left corner of the raster grid, which is associated with a location in a coordinate reference system). Raster data are fundamentally different from vector data in that they are referenced to a regular grid of rectangular (usually square) cells.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |