Commit fbe0a9c3 authored by de Lavenne Alban's avatar de Lavenne Alban
Browse files

docs: improve again the handling of possible errors with whitebox

parent 9ef14aca
No related merge requests found
Showing with 12 additions and 9 deletions
+12 -9
......@@ -2,6 +2,8 @@
^\.Rproj\.user$
package.json
package-lock.json
settings.json
vignettes/settings.json
node_modules
^doc$
^Meta$
......@@ -17,3 +17,4 @@ MD5
node_modules
package.json
package-lock.json
settings.json
......@@ -2,7 +2,7 @@ Package: transfR
Type: Package
Title: Transfer of Hydrograph from Gauged to Ungauged Catchments
Version: 1.0.7
Date: 2023-01-23
Date: 2023-01-24
Authors@R: c(
person("Alban", "de Lavenne", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9448-3490"), email = "alban.delavenne@inrae.fr"),
person("Christophe", "Cudennec", role = c("ths"), comment = c(ORCID = "0000-0002-1707-8926"), email = "christophe.cudennec@agrocampus-ouest.fr"),
......
......@@ -40,7 +40,7 @@ The `elevatr` package allows retrieving grids (rasters) of elevation data worldw
It is necessary to assign a geographic projection for the catchment delineation and hydraulic length maps with the `whitebox` package. We chose to use the Lambert93 projection, the official projection for maps of metropolitan France, for which the [EPSG code is 2154](https://epsg.io/2154).
```{r, download_dem, echo=TRUE, message=FALSE, warning=FALSE, eval=TRUE, results='hide'}
```{r, download_dem, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
library(elevatr)
library(rgdal) # Still often needed by elevatr
library(progress) # Still often needed by elevatr
......@@ -107,7 +107,7 @@ if(!wbt_init()){
}
```
```{r, burn_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
```{r, burn_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
library(transfR)
library(whitebox)
......@@ -158,7 +158,7 @@ The `whitebox` package provides all the tools to perform a usual catchment delin
* [Delimit the catchments](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#Watershed).
```{r, extract_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
```{r, extract_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
# Remove the depressions on the DEM
whitebox::wbt_fill_depressions(dem = "dem_100m_burn.tif",
output = "dem_fill.tif",
......@@ -200,7 +200,7 @@ if(inherits(try_chunk, "try-error")){
Coordinates of the outlets are retrieved from [hydro.eaufrance.fr](https://www.hydro.eaufrance.fr/) and snapped to the pixel of the river network that is consistent with the previously defined flow directions.
```{r, delineate_catchments, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
```{r, delineate_catchments, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
# Localize the outlets of the studied catchments (with manual adjustments to help snapping)
outlets_coordinates <- data.frame(id = names(Blavet$hl),
X = c(254010.612,255940-100,255903,237201,273672,265550),
......@@ -228,9 +228,9 @@ for(id in outlets_snapped$id){
wd = wbt_wd)
# Vectorize catchments
drainage <- read_stars(file.path(wbt_wd, paste0(id, "_catchment.tif")))
contours <- st_contour(drainage, breaks = 1) |> st_cast("POLYGON")
contours <- contours[which.max(st_area(contours)),]
catchments <- rbind(catchments, st_sf(data.frame(id, geom = st_geometry(contours))))
contours <- st_contour(drainage, breaks = 1) |> st_geometry() |> st_cast("POLYGON")
contours <- contours[which.max(st_area(contours))]
catchments <- rbind(catchments, st_sf(data.frame(id, geom = contours)))
}
```
......@@ -274,7 +274,7 @@ The `whitebox` package does not provide a function to compute hydraulic length d
Flow path lengths are computed once for all the study area. For each catchment, this raster is then trimmed (i.e. removing NA values outside the bounding box of the catchment) and the values of flow path lengths are corrected such as the minimum flow path length is equal to half a pixel width/height. The hydraulic lengths are finally gathered in a list as expected by the `as_transfr()` function.
```{r, hydraulic_length, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
```{r, hydraulic_length, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
# Compute hydraulic length
whitebox::wbt_downslope_flowpath_length(d8_pntr = "d8.tif",
output = "fpl.tif",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment