I have two raster layers and I want to perform some analysis and save the result (a raster) based on the name of the input raster + some value. The value is determined by a part of a function (see code bellow).
For example if my input is called tirs, the output should be tirs2, if the number I used for sigma is 0.2. If I use sigma = 0.65, the output should be tirs65. As you can see, although the sigma is a decimal number, the output should not include the "0." part. (Note that I do sd = a number * 460, I do not want the * 460 to be included in the output name).
Lastly, the sigma value is from 0.2 to 0.9 with step 0.05.
The analysis I am using is the following:
library(gridkernel)
library(gridprocess)
library(raster)
tirs = raster("path/tirs.tif") # raster to be upscaled
ntl = raster("path/ntl.tif") # raster to be resampled with
g = as.grid(tirs)
smoothed = gaussiansmooth(g,
sd = 0.2 * 460,
max.r = 100)
r <- raster(smoothed)
resample(r,
ntl,
method = "ngb",
filename = "path/nn/tirs2.tif",
overwrite = T)
I have tried to do this:
for (i in seq(from = 0.2, to = 0.9, by = 0.05)) {
g = as.grid(tirs)
smoothed = gaussiansmooth(g, sd = i * 460, max.r = 100)
r <- raster(smoothed)
resample(r,
ntl,
method = "ngb")
file_name <- paste0("tirs", i, ".txt")
full_file_path = paste0("path/nn", "/", file_name)
writeRaster(r, full_file_path, format = "GTiff")
}
but unsuccessfully. It does not smooth and resample the images.
The question is similar to this one, but whenever I am trying to to add the resample function, the output's raster pixel size is the same as my input (no smoothing and no resampling, just the name it changes).
Here are my raster layers:
tirs = raster(ncols=1818, nrows=372, xmn=32400, xmx=214200, ymn=262100, ymx=299300, crs='+proj=tmerc +lat_0=4 +lon_0=4.5 +k=0.99975 +x_0=230738.26 +y_0=0 +a=6378249.145 +rf=293.465 +units=m +no_defs')
ntl = raster(ncols=363, nrows=75, xmn=32618.9705113234, xmx=214118.970511323, ymn=261831.765752868, ymx=299331.765752868, crs='+proj=tmerc +lat_0=4 +lon_0=4.5 +k=0.99975 +x_0=230738.26 +y_0=0 +a=6378249.145 +rf=293.465 +units=m +no_defs')