Skip to content

HELP with RPyGeo and RSAGA slope function

2 messages · gianni lavaredo, Alexander Brenning

#
Dear Gianni,

ArcGIS is not that flexible; it does not allow you to directly create an 
ASCII raster as an output of a geoprocessing tool. Try this to create an 
ESRI raster "SLOPE" and then convert the result to ASCII:

setwd("C:/work")
env = rpygeo.build.env(overwriteoutput = 1,
            workspace = getwd())
rpygeo.geoprocessor(fun = "ASCIIToRaster_conversion",
      args = list("DEM.asc","DEM"), env=env)
rpygeo.Slope.sa("DEM","SLOPE",unit="PERCENT_RISE", env=env)
rpygeo.geoprocessor(fun = "RasterToASCII_conversion",
      args = list("SLOPE","SLOPE.asc"), env=env)
rpygeo.Delete.management("DEM", env=env)
rpygeo.Delete.management("SLOPE", env=env)


Regarding the (much faster) RSAGA solution, try this:

setwd("C:/work")
rsaga.esri.to.sgrd("DEM")
rsaga.slope("DEM","SLOPErad")
# convert to slope in percent:
rsaga.grid.calculus("SLOPErad","SLOPE", formula="100*tan(a)")
rsaga.sgrd.to.esri("SLOPE", prec = 4)
unlink(c("SLOPErad.*", "SLOPE.?grd", "SLOPE.sdat",
            "DEM.?grd", "DEM.sdat"))

I hope this helps...

cheers
  Alex


P.S.: You could also you the following call for converting ESRI raster 
to ASCII...

rpygeo.RasterToASCII.conversion("C:/work/SLOPE","C:/work/SLOPE.asc")

using the following function that is included in the next release of 
RPyGeo (to be available in the next days):

rpygeo.RasterToASCII.conversion = function(in.raster,
	out.ascii.file, ...)
{
     out.ascii.file = default.file.extension(out.ascii.file, ".asc")
     if (!(tolower(get.file.extension(out.ascii.file)) %in% c(".asc",
         ".txt")))
         stop("'out.ascii.file' must have extension '.asc' or '.txt'.\n")
     args = list(in.raster, out.ascii.file)
     rpygeo.geoprocessor(fun = "RasterToASCII_conversion", args = args,
         ...)
}
gianni lavaredo wrote: