I am working on a script that should help me find potential realese areas for avalanches. I am using the RSAGA package for R, I have downloaded SAGA GIS that is required to run these tools. When I try to create raster object of slope raster I get an error code that says:
Error in rsaga.geoprocessor("ta_morphometry", 23, env = myenv, list(DEM = "outputRas.sgrd", : object 'myenv' not found
This is my env- settings from start:
#Installing RSAGA
install.packages("RSAGA", dependencies = TRUE)
inputRas = "C:/Users/Lizac/OneDrive/Dokument/PRA/kittel_studyarea.asc"
outPRA = "K_PRA.asc"
HS = 2.3
smooth = "Regular"
wind = 180
windTol = 30
work_dir = "C:/Users/Lizac/OneDrive/Dokument/PRA"
library(sp)
library(gstat)
library(shapefiles)
library(foreign)
library(methods)
library(plyr)
#library(rgdal)
library(raster)
library(RSAGA)
#library(maptools)
library(Rsagacmd)
#### preliminary calculations ####
dir.saga <- "C:/Program Files/saga-8.4.1_x64"
myenv=rsaga.env(workspace=work_dir,
path="C:/Program Files/saga-8.4.1_x64",
modules="C:/Program Files/saga-8.4.1_x64/modules"")
setwd(work_dir)
and this is my tool- script:
#### calculate ruggedness at different scales #####
for (i in 1:i_max ) {
#calculate slope and aspect ####
slope_name <- paste("slope", i, sep="")
aspect_name <- paste("aspect", i, sep="")
rsaga.geoprocessor("ta_morphometry",23,env=myenv,list(
DEM ="outputRas.sgrd",
SLOPE = slope_name,
ASPECT = aspect_name,
SIZE=i,
TOL_SLOPE="1.00000",
TOL_CURVE="0.000100",
EXPONENT="0.00000",
ZSCALE="1.000000",
CONSTRAIN=FALSE))
rsaga.sgrd.to.esri(slope_name, slope_name,
format = "ascii", georef = "corner", prec = 2)
rsaga.sgrd.to.esri(aspect_name, aspect_name,
format = "ascii", georef = "corner", prec = 2)
#create raster object of slope raster
f <- list.files(pattern=paste(slope_name, ".asc$", sep=""), full.names=TRUE)
slope <- raster(f)
f <- list.files(pattern=paste(aspect_name, ".asc$", sep=""), full.names=TRUE)
aspect <- raster(f)
#convert to radians
slope_rad <- slope*pi/180
aspect_rad <- aspect*pi/180
#calculate xyz components
xy_raster <- sin(slope_rad)
z_raster <- cos(slope_rad)
x_raster <- sin(aspect_rad) * xy_raster
y_raster <- cos(aspect_rad) * xy_raster
xsum_raster <- focal(x_raster, w=matrix(1,3,3), fun=sum)
ysum_raster <- focal(y_raster, w=matrix(1,3,3), fun=sum)
zsum_raster <- focal(z_raster, w=matrix(1,3,3), fun=sum)
result_raster <- sqrt((xsum_raster)^2 + (ysum_raster)^2 + (zsum_raster)^2)
ruggedness_raster <- (1- (result_raster/9))
rugg_name <- paste("ruggedness", i, sep="")
writeRaster(ruggedness_raster, rugg_name, format="ascii", overwrite=TRUE)
}
Any ideas on how I can solve this?
Thank you so much
I have had a couple of error with script and I am new to this so I am do not even know where to start to solve this problem. I have googled it and tried to read a couple of other forums without getting any wiser. All help is definitely appreciated!