Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See our guide on [how to create a great issue](https://code-review.tidyverse.org
### Code style

* New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.
You can use the [air](https://github.com/posit-dev/air) to apply these styles, but please don't restyle code that has nothing to do with your PR.

* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(wbw_data_type)
export(wbw_download_sample_data)
export(wbw_ext)
export(wbw_fill_missing_data)
export(wbw_gaussian_curvature)
export(wbw_gaussian_filter)
export(wbw_high_pass_filter)
export(wbw_high_pass_median_filter)
Expand All @@ -41,13 +42,17 @@ export(wbw_is_int)
export(wbw_is_rgb)
export(wbw_majority_filter)
export(wbw_max_procs)
export(wbw_maximal_curvature)
export(wbw_maximum_filter)
export(wbw_mean_curvature)
export(wbw_mean_filter)
export(wbw_median_filter)
export(wbw_minimal_curvature)
export(wbw_minimum_filter)
export(wbw_multidirectional_hillshade)
export(wbw_olympic_filter)
export(wbw_percentile_filter)
export(wbw_profile_curvature)
export(wbw_random_sample)
export(wbw_range_filter)
export(wbw_read_raster)
Expand Down
159 changes: 78 additions & 81 deletions R/WhiteboxClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @keywords class
#'
#' @description
#' Defines the spatial extent of a raster dataset using coordinates for
#' Defines the spatial extent of a raster dataset using coordinates for
#' the west, east, south, and north boundaries.
#'
#' @param west \code{double} Western boundary coordinate
Expand All @@ -11,46 +11,44 @@
#' @param north \code{double} Northern boundary coordinate
#'
#' @export
WhiteboxExtent <-
S7::new_class(
name = "WhiteboxExtent",
package = "wbw",
properties = list(
west = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'west' must be a single numeric value")
}
WhiteboxExtent <- S7::new_class(
name = "WhiteboxExtent",
package = "wbw",
properties = list(
west = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'west' must be a single numeric value")
}
),
east = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'east' must be a single numeric value")
}
}
),
east = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'east' must be a single numeric value")
}
),
south = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'south' must be a single numeric value")
}
}
),
south = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'south' must be a single numeric value")
}
),
north = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'north' must be a single numeric value")
}
}
),
north = S7::new_property(
class = S7::class_double,
validator = function(value) {
if (length(value) != 1) {
return("'north' must be a single numeric value")
}
)
}
)
)

)

#' WhiteboxRaster Class
#' @keywords class
Expand All @@ -71,53 +69,52 @@ WhiteboxExtent <-
#' \item{extent}{\code{WhiteboxExtent} Spatial extent of the raster}
#' }
#' @export
WhiteboxRaster <-
S7::new_class(
name = "WhiteboxRaster",
package = "wbw",
properties = list(
name = S7::class_character,
source = S7::class_any,
stats = S7::new_property(
class = S7::class_character,
getter = function(self) {
check_env(wbe)
wbe$raster_summary_stats(self@source)
}
),
min = S7::new_property(
class = S7::class_double,
getter = function(self) {
extract_stat(self@stats, "minimum")
},
validator = function(value) {
if (!is.numeric(value) || length(value) != 1) {
return("@min must be a single numeric value")
}
WhiteboxRaster <- S7::new_class(
name = "WhiteboxRaster",
package = "wbw",
properties = list(
name = S7::class_character,
source = S7::class_any,
stats = S7::new_property(
class = S7::class_character,
getter = function(self) {
check_env(wbe)
wbe$raster_summary_stats(self@source)
}
),
min = S7::new_property(
class = S7::class_double,
getter = function(self) {
extract_stat(self@stats, "minimum")
},
validator = function(value) {
if (!is.numeric(value) || length(value) != 1) {
return("@min must be a single numeric value")
}
),
max = S7::new_property(
class = S7::class_double,
getter = function(self) {
extract_stat(self@stats, "maximum")
},
validator = function(value) {
if (!is.numeric(value) || length(value) != 1) {
return("@max must be a single numeric value")
}
}
),
max = S7::new_property(
class = S7::class_double,
getter = function(self) {
extract_stat(self@stats, "maximum")
},
validator = function(value) {
if (!is.numeric(value) || length(value) != 1) {
return("@max must be a single numeric value")
}
)
# extent = S7::new_property(
# class = WhiteboxExtent,
# getter = function(self) {
# conf <- self@source$configs
# WhiteboxExtent(
# west = conf$west,
# east = conf$east,
# south = conf$south,
# north = conf$north
# )
# }
# )
}
)
# extent = S7::new_property(
# class = WhiteboxExtent,
# getter = function(self) {
# conf <- self@source$configs
# WhiteboxExtent(
# west = conf$west,
# east = conf$east,
# south = conf$south,
# north = conf$north
# )
# }
# )
)
)
72 changes: 37 additions & 35 deletions R/checks.R
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
#' Check if package is installed
#' @rdname checks
#' @keywords internal
check_package <-
function(package) {
if (!requireNamespace(package, quietly = TRUE)) {
stop(paste(package, "is required but not installed."))
}
check_package <- function(package) {
if (!requireNamespace(package, quietly = TRUE)) {
stop(paste(package, "is required but not installed."))
}
}

#' Check if whitebox environment is present
#' @rdname checks
#' @keywords internal
check_env <-
function(env = wbe) {
checkmate::assert_class(
env,
classes = c(
"whitebox_workflows.WbEnvironment",
"python.builtin.WbEnvironmentBase",
"python.builtin.object"
)
check_env <- function(env = wbe) {
checkmate::assert_class(
env,
classes = c(
"whitebox_workflows.WbEnvironment",
"python.builtin.WbEnvironmentBase",
"python.builtin.object"
)
}
)
}

#' Check input file extension
#' @rdname checks
#' @keywords internal
check_input_file <-
function(file_name, type) {
type <- checkmate::matchArg(type, c("vector", "raster"))
check_input_file <- function(file_name, type) {
type <- checkmate::matchArg(type, c("vector", "raster"))

if (type == "vector") {
checkmate::assertFileExists(
file_name,
access = "r",
extension = c(".shp")
)
} else if (type == "raster") {
checkmate::assertFileExists(
file_name,
access = "r",
extension = c(
".tif", ".tiff", ".sdat", ".sgrd", ".rst",
".rdc", ".grd", ".flt", ".bil"
)
if (type == "vector") {
checkmate::assertFileExists(
file_name,
access = "r",
extension = c(".shp")
)
} else if (type == "raster") {
checkmate::assertFileExists(
file_name,
access = "r",
extension = c(
".tif",
".tiff",
".sdat",
".sgrd",
".rst",
".rdc",
".grd",
".flt",
".bil"
)
}
)
}


}
Loading
Loading