我想使用R中的SAGA工具之一,它给了我一个我不理解的错误,而我在其他地方找不到解决方案。
对于此特定代码,我尝试在栅格DEM上填充汇点,但是当我尝试使用任何其他工具时遇到相同的问题。
这是我的代码
library(RSAGA)
library(raster)
wd="C:/Users/charlie/Desktop/Cartographie_risques"
setwd(wd)
myenv=rsaga.env(workspace = wd, path = "C:/Program Files/QGIS 2.18/apps/saga-ltr")
#Read the raster and prepare the dataset
input.single.raster=raster("C:/Users/charlie/Desktop/Cartographie_risques/Localisation_alea/Lacs_glaciaires/MNT_sans_glaciers/Clipped_limite_1.tif")
#Launch the calculation
rsaga.geoprocessor("sim_qm_of_esp",1,list(DEM=input.single.raster,FILLED="Filled",SINKS="Sinks",DZFILL=0.01),env=myenv)
然后我收到此消息
> rsaga.geoprocessor("sim_qm_of_esp",1,list(DEM=input.single.raster,FILLED="Filled",SINKS="Sinks",DZFILL=0.01),env=myenv)
Unexpected parameter '+zone=32'
SAGA Version: 6.3.0 (64 bit)
library path: C:\Users\CHARLI~1\Desktop\saga-6.3.0_x64\saga-6.3.0_x64\tools\
library name: sim_qm_of_esp
library : sim_qm_of_esp
tool : Fill Sinks (QM of ESP)
identifier : 1
author : O.Conrad (c) 2013
processors : 6 [6]
Usage: saga_cmd sim_qm_of_esp 1 [-DEM <str>] [-FILLED <str>] [-SINKS <str>] [-DZFILL <double>]
-DEM:<str> DEM
Grid (input)
-FILLED:<str> DEM without Sinks
Grid (output)
-SINKS:<str> Sinks
Grid (optional output)
-DZFILL:<double> Fill Increment
Floating point
Minimum: 0.000000
Default: 0.010000
Warning message:
In system(command, intern = intern, show.output.on.console = show.output.on.console, :
running command '"C:/Users/charlie/Desktop/saga-6.3.0_x64/saga-6.3.0_x64/saga_cmd.exe" -f=q sim_qm_of_esp 1 -DEM "new(\"RasterLayer\", file = new(\".RasterFile\", name = \"C:\\Users\\charlie\\Desktop\\Cartographie_risques\\Localisation_alea\\Lacs_glaciaires\\MNT_sans_glaciers\\Clipped_limite_1.tif\", datanotation = \"FLT4S\", byteorder = \"little\", nodatavalue = -Inf, NAchanged = FALSE, nbands = 1, bandorder = \"BIL\", offset = 0, toptobottom = TRUE, blockrows = 5, blockcols = 366, driver = \"gdal\", open = FALSE), data = new(\".SingleLayerData\", values = logical(0), offset = 0, gain = 1, inmemory = FALSE, fromdisk = TRUE,
isfactor = FALSE, attributes = list(), haveminmax = TRUE, min = 825.53076171875, max = 3009.1381835938, band = 1, unit = \"\", names = \"Clipped_limite_1\"), legend = new(\".RasterLegend\", type = character(0), values = logical(0), color = logical(0), names = logical(0), colortable = logical(0)), title = character(0), extent = new(\"Extent\", x [... truncated]
似乎“意外参数”与投影有关,但我不明白为什么会出问题以及是否确实是问题。
查理
答案 0 :(得分:0)
RSAGA不适用于RasterLayer对象作为输入参数。它始终使用硬盘上的文件。 rsaga.geoprocessor
调用SAGA-GIS的命令行解释器。 SAGA GIS无法处理R对象,并且无法自动将R对象转换为RSAGA中的文件。
此代码应该有效:
library(RSAGA)
library(raster)
# Set environment
setwd("C:/Users/charlie/Desktop/Cartographie_risques")
myenv <- rsaga.env(workspace = wd, path = "C:/Program Files/QGIS 2.18/apps/saga-ltr")
# Convert tiff to sgrd
r <- raster("C:/Users/charlie/Desktop/Cartographie_risques/Localisation_alea/Lacs_glaciaires/MNT_sans_glaciers/Clipped_limite_1.tif")
writeRaster(r, "C:/Users/charlie/Desktop/Cartographie_risques/Localisation_alea/Lacs_glaciaires/MNT_sans_glaciers/Clipped_limite_1.sdat")
# Set raster path
input.single.raster <- "C:/Users/charlie/Desktop/Cartographie_risques/Localisation_alea/Lacs_glaciaires/MNT_sans_glaciers/Clipped_limite_1.sgrd"
#Launch the calculation
rsaga.geoprocessor("sim_qm_of_esp",1,list(DEM=input.single.raster,FILLED="Filled",SINKS="Sinks",DZFILL=0.01),env=myenv)
请注意,我们仅使用光栅包将tiff文件转换为sgrd文件。然后,我们将硬盘上的sgrd文件用作输入参数。