# 2) Set the extent (geographic 'bounding box') of the new raster # 1) Create a new raster object with the correct 'resampled' number of cells. # both dimensions (four times the number of cells) # into a NEW raster with 2x spatial resolution in ![]() # Resample a satellite image, stored in a GeoTiff file # s prints a vector of resampled cell values. # This code produces a resampled raster, 's', # second method: use the resample() method from raster package WriteRaster(FineResampRaster,filename=sOutFile,format="GTiff",datatype="INT1U",overwrite=TRUE) SOutFile <- sprintf("FineSubsamp%s",inFiles) WriteRaster(CoarseResampRaster,filename=sOutFile,format="GTiff",datatype="INT1U",overwrite=TRUE)įineResampRaster <- disaggregate(inputRaster,fact=resampleFactor,fun=mean) SOutFile <- sprintf("CoarseSubsamp%s",inFiles) # and FINER (smaller cells) resolutions, respectivelyĬoarseResampRaster <- aggregate(inputRaster,fact=resampleFactor,fun=mean) # The aggregate() / disaggregate methods resample rasters to COARSER (bigger cells) Message(sprintf("resampling file: %s",inFiles)) # Note: these images do not have same spatial extent, so they cant be stored # Within the same loop, obtain the (geographic) extent of each component. # Read the mosaic components, stored in a subfolder, into a raster object list. ResampleFactor <- 4 # For test, subsample incoming image by factor of 10 # spatial resolution using the R raster package. # This function demonstrates resampling of raster images to a new This would normally be a SpatRaster that you already have from another data source. Therefore, the preferred approach is to provide a template to which you want the output to align with. You can do that like this: u1 <- project(r, "+proj=utm +zone=32")īut, unlike for vector data, the transformation of raster data is not well-defined. It could also be that you want to transform raster data to a geometry with another coordinate reference system ("map projection"). In that case you can use resampleĮxample of a non-aligned SpatRaster: x <- rast(r) But to combine raster data from different sources, you may need to match the geometry of a raster that does not align. ![]() You can also go the other way and disaggregate: d <- disagg(a2, 2)Īggregate can only combine entire cells. You can use a different factor for the rows and columns, and also different aggregation functions (the default is "mean") a2 <- aggregate(r, c(2,3), fun=sum) To go from 30 to 120m is a factor of 4 a1 <- aggregate(r, 4) These days we can use terra, the replacement for the raster packageį <- system.file("ex/elev.tif", package="terra")Īggregate raster cells.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |