Error in rsaga.geoprocessor("ta_morphometry", 23, env = myenv, list(DEM = "outputRas.sgrd", : object 'myenv' not found

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"




####  preliminary calculations ####

dir.saga <- "C:/Program Files/saga-8.4.1_x64"

                path="C:/Program Files/saga-8.4.1_x64",
                modules="C:/Program Files/saga-8.4.1_x64/modules"") 


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="")
    DEM ="outputRas.sgrd",
    SLOPE = slope_name,
    ASPECT = aspect_name,
    CONSTRAIN=FALSE)), slope_name,
                     format = "ascii", georef = "corner", prec = 2), 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 :slight_smile:

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!

Try removing the last “

I tried to do that but it still does not find the tool...

In my SAGA- GIS download folder I cannot find a map that is called "module" either. It seems like a very easy fix, but I just do not get it. :slight_smile:

Try this

dir("C:/Program Files/saga-8.4.1_x64"

and report what it shows?

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.