12/28/2023 0 Comments Function raster in rIt is also possible to extract focal window as a ame or list object. It is often necessary to extract raster values of covariates that will be used in specifying a model.īecause the resulting vector is ordered we can easily add it to sp vector object <- rVal=extract(r, The raster has a build in function "extract" to pull raster values based on specified spatial locations, cell indexs, sp point objects and sp polygon objects. First, let’s create some data to work with. Now we will move on to raster class objects. Remember, R gives you exactly what you ask for! If we account for the NA's the we get the real count. This is because R is including NA vlaues in each query. Here you see that, based on the query, we end up with a count of 13121 but there are only 8112 observations in the data. As in sp point and polygon objects, the attribute data is held in the slot.įor example data we will use the id data available in sp. This is the object type that results from reading data in via rgdal and is structured in much the same way that as an sp SpatialPointsDataFrame. Let’s start with introducing the SpatialGridDataFrame class. This results in a raster class object or the specified output. You can also use GDALinfo to retrieve information about the raster without reading it into R.Īlternately, you can use readRaster/writeRaster in the raster package to ensure that the object is memory safe. This results in a sp spatial pixels object or the specified output. You can use readGDAL/writeGDAL for reading and writing rasters in a large variety of formats. This is quite nice for handling large rasters or raster stacks. Using rgdal reads the entire raster into memory whereas raster assesses the size of the raster and will, if memory safe, read it into memory otherwise index it out of memory. There are two primary ways to read rasters through rgdal or raster libraries. ![]() There are functions available that act as wrappers for coercion, making it unnecessary to understand the nuances of raster topology classes at this point. Understanding these classes can be important for coercion or setting up empty rasters but I am not covering these specifics in this tutorial. The SpatialPixels and SpatialGrid classes are classes representing array/point and pixel/polygon topology and are not currently relevant. The spatstat image class is specific to point process analysis and will be covered in a tutorial specific to this type of analysis. There are four relevant raster object classes: “SpatialPixelsDataFrame”, “SpatialGridDataFrame” in the sp library, “raster” in the raster library and “image” in spatstat. In this tutorial I will introduce raster classes, reading raster objects, manipulation, focal functions, vector extraction and writing functions.įirst, let’s add the R libraries we will need The ability to access raster data, without reading it into R, has provided a large advantage in specifying spatial models. ![]() ![]() ![]() The raster library provides the capacity to hold rasters out-of-memory allowing processing of larger data as well as prediction to multiple rasters. The difficulty in raster analysis is that R holds everything in active memory making the handling of large rasters problematic. Aside from manipulation matrix and array objects, the primary ways to handle rasters in R are the raster, rgdal and sp libraries.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |