-
Notifications
You must be signed in to change notification settings - Fork 31
/
README.Rmd
249 lines (167 loc) · 10.6 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---
output: md_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
dev = 'jpeg',
out.width = "100%"
)
```
# whitebox
<!-- badges: start -->
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/whitebox)](https://cran.r-project.org/package=whitebox)
[![CRAN download count](https://cranlogs.r-pkg.org/badges/grand-total/whitebox)](https://cranlogs.r-pkg.org/badges/grand-total/whitebox)
[![whitebox Manual](https://img.shields.io/badge/docs-HTML-informational)](https://whiteboxR.gishub.org/reference/index.html)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/license/MIT)
[![R-CMD-check](https://github.com/opengeos/whiteboxR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/opengeos/whiteboxR/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/opengeos/whiteboxR/branch/master/graph/badge.svg)](https://app.codecov.io/gh/opengeos/whiteboxR)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/brownag/whitebox-r-binder/master?urlpath=rstudio)
[![Donate](https://img.shields.io/badge/Donate-Buy%20me%20a%20coffee-yellowgreen.svg)](https://buymeacoffee.com/giswqs)
<!-- badges: end -->
**WhiteboxTools** R Frontend.
This repository is related to the **whitebox** R package for geospatial analysis, which is an R frontend of a stand-alone executable command-line program called **[WhiteboxTools](https://github.com/jblindsay/whitebox-tools)**.
* Authors: John Lindsay (<https://jblindsay.github.io/ghrg/index.html>)
* Contributors:
* Qiusheng Wu (<https://wetlands.io>)
* Andrew G. Brown (<https://humus.rocks>)
* GitHub repo: <https://github.com/opengeos/whiteboxR>
* CRAN link: <https://cran.r-project.org/package=whitebox>
* WhiteboxTools: <https://github.com/jblindsay/whitebox-tools>
* User Manual: <https://jblindsay.github.io/wbt_book/>
* Free software: [MIT license](https://opensource.org/license/MIT)
**Contents**
1. [Description](#description)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Available Tools](#available-tools)
5. [Contributing](#contributing)
6. [License](#license)
7. [Reporting Bugs](#reporting-bugs)
## Description
The **whitebox** R package is built on **WhiteboxTools**, an advanced geospatial data analysis platform developed by Prof. John Lindsay ([webpage](https://jblindsay.github.io/ghrg/index.html); [jblindsay](https://github.com/jblindsay)) at the University of Guelph's [Geomorphometry and Hydrogeomatics Research Group](https://jblindsay.github.io/ghrg/index.html). *WhiteboxTools* can be used to perform common geographical information systems (GIS) analysis operations, such as cost-distance analysis, distance buffering, and raster reclassification. Remote sensing and image processing tasks include image enhancement (e.g. panchromatic sharpening, contrast adjustments), image mosaicing, numerous filtering operations, simple classification (k-means), and common image transformations. *WhiteboxTools* also contains advanced tooling for spatial hydrological analysis (e.g. flow-accumulation, watershed delineation, stream network analysis, sink removal), terrain analysis (e.g. common terrain indices such as slope, curvatures, wetness index, hillshading; hypsometric analysis; multi-scale topographic position analysis), and LiDAR data processing. LiDAR point clouds can be interrogated (LidarInfo, LidarHistogram), segmented, tiled and joined, analyzed for outliers, interpolated to rasters (DEMs, intensity images), and ground-points can be classified or filtered. *WhiteboxTools* is not a cartographic or spatial data visualization package; instead it is meant to serve as an analytical backend for other data visualization software, mainly GIS. Suggested citation: Lindsay, J. B. (2016). Whitebox GAT: A case study in geomorphometric analysis. _Computers & Geosciences_, 95, 75-84. doi: http://dx.doi.org/10.1016/j.cageo.2016.07.003
## Installation
There are three ways to install the **whitebox** R package.
### 1. CRAN
**whitebox** is now available on [CRAN](https://cran.r-project.org/package=whitebox), so you can install it with:
```R
install.packages("whitebox")
```
### 2. GitHub
You can alternatively install the development version of **whitebox** from [GitHub](https://github.com/opengeos/whiteboxR) as follows:
```R
if (!require("remotes")) install.packages('remotes')
remotes::install_github("opengeos/whiteboxR", build = FALSE)
```
## Usage
The function `wbt_init()` checks the path to the 'WhiteboxTools' binary.
```r
wbt_init()
```
It (invisibly) returns a logical (TRUE/FALSE) value reflecting whether a file is found at one of the default paths, including those specified by package options. See `?whitebox::whitebox`.
If you have 'WhiteboxTools' installed already but in a non-standard location run `wbt_init(exe_path=...)` to set up your options for your current R session.
```{r, eval=FALSE}
wbt_init(exe_path = 'C:/home/user/path/to/whitebox_tools.exe')
```
Additional arguments to `wbt_init()` can set other package options, such as whether tools print their standard console output with `cat()`.
If you want to turn this off, set `verbose = FALSE`, for instance:
```{r, eval=FALSE}
wbt_init(exe_path = 'C:/home/user/path/to/whitebox_tools.exe', verbose = FALSE)
```
## Documentation
For whitebox package documentation in R, ask for help:
```r
??whitebox
```
For list of functions, try the `wbt_` prefix in your search:
```r
??wbt_
```
A complete list of functions available in the **whitebox** R package can be found [HERE](https://whiteboxR.gishub.org/reference/index.html).
Check out this [demo](https://whiteboxR.gishub.org/articles/demo.html) for examples.
## Installing 'WhiteboxTools'
The quickest way to get started if you are on 64-bit Windows, Linux or MacOS architectures is to download and install the 'WhiteboxTools' binary. Linux binaries compiled with 'musl' instead of 'glibc' on Ubuntu 22.04 are available with `platform="linux_musl"`. On MacOS, Intel and Apple 'M' series processors ('arm64') are supported.
A method `install_whitebox()` is provided to download a version of the binaries that corresponds to the wrapper functions available in the package.
```{r, eval=FALSE}
whitebox::install_whitebox()
```
By default this will install 'WhiteboxTools' to your whitebox R package data directory (see `wbt_data_dir()`), subdirectory "WBT".
## whitebox
**How do I run tools?**
Tool names in the whitebox R package can be called by corresponding function using `wbt_snake_case()` naming convention (e.g. `wbt_lidar_info()` R function for `"LidarInfo"` 'WhiteboxTools' tool name).
First we load the library and perform any necessary setup.
```{R}
library(whitebox)
# set up as needed
wbt_init()
```
Many 'WhiteboxTools' will take GeoTIFF files as input, but 'WhiteboxTools' supports several grid input formats. There is a sample Digital Elevation Model (DEM) included in the whitebox package. You can get path as follows for this demo:
```{R}
# Set input raster DEM file
dem <- sample_dem_data()
```
We will use this DEM in a sequence of 'WhiteboxTools' processing routines.
Run tools by passing file paths for the input and output files.
1. Apply feature-preserving smoothing (_FeaturePreservingSmoothing_)
2. Breach depressions in a DEM (_BreachDepressions_)
3. Calculate D-Infinity flow accumulation (_DInfFlowAccumulation_)
The `filter` argument to `wbt_feature_preserving_smoothing()` sets the size of the filter kernel.
```{r}
## 1. FeaturePreservingSmoothing
wbt_feature_preserving_smoothing(
dem = dem,
output = "./smoothed.tif",
filter = 9
)
## 2. BreachDepressions
wbt_breach_depressions(dem = "./smoothed.tif", output = "./breached.tif")
## 3. DInfFlowAccumulation
wbt_d_inf_flow_accumulation(input = dem, output = "./flow_accum.tif")
```
```{r terra-plot-facc}
if (requireNamespace('terra')) {
terra::plot(terra::rast("./flow_accum.tif"))
}
```
**About 'WhiteboxTools'**
```{r}
library(whitebox)
# cat() output in non-interactive mode
wbt_verbose(TRUE)
# Prints the whitebox-tools help...a listing of available commands
wbt_help()
# Prints the whitebox-tools license
wbt_license()
# Prints the whitebox-tools version
wbt_version()
# Prints the toolbox for a specific tool.
wbt_toolbox("AsciiToLas")
# Lists tools with 'lidar' in tool name or description.
wbt_list_tools("lidar")
# Prints the help for a specific tool.
wbt_tool_help("lidar_info")
# Retrieves the tool parameter descriptions for a specific tool.
wbt_tool_parameters("slope")
# View the source code for a specific tool on the source code repository.
wbt_view_code("breach_depressions")
```
## Available Tools
The **[WhiteboxTools](https://github.com/jblindsay/whitebox-tools)** library currently contains more than **`r nrow(wbttools)`** tools, which are each grouped based on their main function into one of the following categories: Data Tools, GIS Analysis, Hydrological Analysis, Image Analysis, LiDAR Analysis, Mathematical and Statistical Analysis, Stream Network Analysis, and Terrain Analysis. For a listing of available tools, complete with documentation and usage details, please see the ['WhiteboxTools' User Manual](https://jblindsay.github.io/wbt_book/available_tools/index.html).
If you are interested in using the 'WhiteboxTools' command-line program, check ['WhiteboxTools' Usage](https://github.com/jblindsay/whitebox-tools#3-usage)
## Contributing
If you would like to contribute to the project as a developer, follow these instructions to get started:
1. Fork the whiteboxR repository (<https://github.com/opengeos/whiteboxR>)
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in the work shall be licensed as the [MIT license](https://opensource.org/license/MIT) without any additional terms or conditions.
## License
The whitebox **R** package is distributed under the [MIT license](https://opensource.org/license/MIT), a permissive open-source (free software) license.
## Reporting Bugs
whitebox is distributed as is and without warranty of suitability for application. If you encounter flaws with the software (i.e. bugs) please report the issue. Providing a detailed description of the conditions under which the bug occurred will help to identify the bug. *Use the [Issues tracker](https://github.com/opengeos/whiteboxR/issues) on GitHub to report issues with the software and to request feature enchancements.* Please do not email Dr. Lindsay directly with bugs.
```{r, echo = FALSE}
unlink(c("smoothed.tif","breached.tif","flow_accum.tif"))
```