TransWikia.com

NA values as result from Grass functions (r.slope.aspect, r.sim.water) in R

Geographic Information Systems Asked on April 26, 2021

As the result from r.slope.aspect I get a raster with only NA values. r.param.scale works, but doesnt generate dx and dy maps, which I both need for r.sim.water function.

Code snippet 1 (initialize GRASS):

initGRASS("C:/GRASS GIS 7.8",
          home = tempdir(),
          mapset = "PERMANENT",
          override = TRUE)

execGRASS(cmd = "g.proj",
          flags = c("c", "quiet"))

use_sp()

writeRAST(x = as(dem_interpoliert,"SpatialGridDataFrame"),
          vname = "interpoliert",
          flags = c("overwrite", "quiet"))


execGRASS("g.region",
          parameters = list(raster = "interpoliert"),
          flags = c("quiet","p"))

Code snippet 2: Generate dx/dy (after using the r.param.scale elev-parameter on "dem_interpoliert", it became "interpoliert_elev"):

execGRASS(cmd = "r.slope.aspect",
          flags = c("overwrite","a","e"),
          parameters = list(elevation ="interpoliert_elev",
                            dx = "E-W_slope",
                            dy = "N-S_slope"))

Large Raster Layer "dem_interpoliert" (for g.region):

class      : RasterLayer 
dimensions : 2945, 3889, 11453105  (nrow, ncol, ncell)
resolution : 0.9, 0.9  (x, y)
extent     : 325999.9, 329500, 5608849, 5611500  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
source     : memory
names      : var1.pred 
values     : 355.4881, 569.02  (min, max)

"interpoliert_elev" (for r.slope.aspect after smoothing "dem_interpoliert" with r.param.scale):

Object of class SpatialGridDataFrame
Object of class SpatialGrid
Grid topology:
  cellcentre.offset cellsize cells.dim
1          326000.3      0.9      3889
2         5608849.9      0.9      2945
SpatialPoints:
                  s1      s2
       [1,] 326000.3 5611500
       [2,] 326001.2 5611500
     ...
     [499,] 326448.5 5611500
     [500,] 326449.4 5611500
 [ erreichte getOption("max.print") --  11452605 Zeilen ausgelassen ]
Coordinate Reference System (CRS) arguments: +proj=utm +zone=33 +ellps=GRS80
+towgs84=0,0,0,0,0,0,0 +units=m +no_defs 

Data summary:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  355.5   423.4   462.7   465.8   506.3   569.0   81864 

Seems like there are a lot of NAs in "interpoliert_elev", right? But result looks fine after plotting:

interpoliert_elev

I also tried to use "dem_interpoliert" with r.slope.aspect, also with NA-result.

Edit:
Now I generated the dx and dy map in QGIS with r.slope.aspect, so that I was able now to use r.sim.water function. So, input data seems to be okay, because using it works in QGIS. r.sim.water executed, but also resulted in Na values (images below).

Code snippet:

execGRASS(cmd = "r.sim.water",
          flags = c("overwrite"),
          parameters = list(elevation = "interpoliert_elev",
                            dx = "dx",
                            dy = "dy",
                            rain_value = 50,
                            man_value = 0.368,
                            depth = "depth",
                            discharge = "discharge",
                            error = "error",
                            nwalkers = 9000000,
                            walkers_output = "walkers",
                            niterations = 180,
                            output_step = 5))


Example of r.sim.water raster input (dy map)


Depth map by r.sim.water. Notice the hole inside.

EDIT:

After assigning a crs to the GRASS- project, r.slope.aspect works now.

execGRASS(cmd = "g.proj", parameters = list(proj4 = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"), flags = c("c", "quiet"))

r.sim.water still doesn’t work and gives a SpatialGridDataFrame with only NA (but no hole anymore).

Thanks
AJ

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP