1

I am trying to run SAGA Wetness Index on a large number of .asc files that were derived from 1-m LiDAR. Due to the large size/amount of data (each .asc file is ~1000 MB and I have ~685 files), I would really like to avoid having to convert the file type to .sgrd.

I understand that ascii files can be read into RSAGA, but I'm not having much luck. I'm trying to get it running on a folder with 6 files in it and I'm trying to run slope only because seems like a simpler calculation than TWI or SAGA WI.

R version: 4.0.3 SAGA version: 2.1.0

My code was as follows:

library(RSAGA)
env <- rsaga.env("C:/Program Files (x86)/SAGA-GIS")

#I first tried this on just one file:

rsaga.slope(in.dem = "filepath", out.slope = "filepath", env = env)

#This was the error message:

library path: C:\PROGRA~2\SAGA-GIS\modules\ta_morphometry.dll library name: Terrain Analysis - Morphometry module name : Slope, Aspect, Curvature author : O.Conrad (c) 2001

Parameters

Grids: No objects Files: filepath Transformation: yes Interpolation: B-Spline Interpolation

loading: filepath Driver: filepath Cells: x 3924, y 5372 Bands: 1 Transformation x' = 324800.000000 + x * 1.000000 + y * 0.000000 Transformation y' = 5563672.000000 + x * 0.000000 + y * -1.000000 loading band [1/1] Slope, Aspect, Curvature: could not initialize data objects Error: executing module [Slope, Aspect, Curvature] Warning message: In system(command, intern = intern, show.output.on.console = show.output.on.console, : running command '"C:/Program Files (x86)/SAGA-GIS/saga_cmd.exe" -f=q ta_morphometry "Slope, Aspect, Curvature" -ELEVATION "filepath" -SLOPE "filepath" -ASPECT "filepath" -METHOD "5"' had status 1

#Also tried:

wd <- setwd("filepath")
 asc.files<-dir(wd, pattern='.asc$')
 asc.files<-substr(basename(asc.files), 1, nchar(basename(asc.files)) - 4)
 asc.files
 for (i in length(asc.files[i])) {
     rsaga.esri.wrapper(fun=rsaga.slope, in.dem=asc.files[i],
                         method="maxslope", in.esri=T, out.esri=T, clean.up=T,
                            out.slope=c(paste("SLOPE",asc.files[i],sep="")), env=env, esri.workspace=
                          "P:/AserLab/Projects/OK_Wetlands/TWI/Test", format="ascii", georef="corner", prec=3)
     }

#error was:
Error: Grid file could not be opened.
Error: input file [bc_082l013_xli1m_utm11_2018.sgrd]
Error: Elevation
Error: executing module [Slope, Aspect, Curvature]

#There was also a long warning message similar to that above.
Vince
  • 20,017
  • 15
  • 45
  • 64
xtina
  • 35
  • 3
  • From the documentation - https://cran.r-project.org/web/packages/RSAGA/RSAGA.pdf read.ascii.grid Read/write ASCII, SAGA and Rd Grid Files – user2856 Jan 20 '21 at 04:14
  • I've tried to use the read.ascii.grid function then apply the slope calculation but I get this error:

    Error in nchar(filename) : no method for coercing this S4 class to a vector

    I think it's having trouble with the ascii grid format.

    – xtina Jan 25 '21 at 18:21

0 Answers0