Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function read_raster_runif #136

Merged
merged 10 commits into from
May 12, 2021
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export(read_habitatquarries)
export(read_habitatsprings)
export(read_habitatstreams)
export(read_namelist)
export(read_raster_runif)
export(read_scheme_types)
export(read_schemes)
export(read_soilmap)
Expand Down Expand Up @@ -99,4 +100,5 @@ importFrom(tidyr,gather)
importFrom(tidyr,nest)
importFrom(tidyr,spread)
importFrom(tidyr,unnest)
importFrom(utils,packageVersion)
importFrom(withr,with_options)
2 changes: 1 addition & 1 deletion R/GRTSmh.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ read_GRTSmh_base4frac <-
#' # what to do.
#' r <- read_GRTSmh_diffres(level = 7)
#' r
#' sp::spplot(r)
#' raster::spplot(r)
#' p <- read_GRTSmh_diffres(level = 7, polygon = TRUE)
#' p
#' plot(p)
Expand Down
18 changes: 18 additions & 0 deletions R/n2khab.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@
"_PACKAGE"

utils::globalVariables(c("."))

#' @importFrom utils packageVersion
.onAttach <- function(libname, pkgname) {
packageStartupMessage("Attaching n2khab version ",
packageVersion("n2khab"), ".\n")
packageStartupMessage(
"When working with raster objects returned by n2khab, you can safely\n",
"mute proj4string degradation warnings:",
"\n\noptions(rgdal_show_exportToProj4_warnings = \"none\")\n\n",
"You must do this before using the n2khab functions ",
"depending on \nrgdal or raster, and before loading ",
"the latter (or sp).\n\n",
"Do note that those warnings are applicable: the generated ",
"proj4string\nof 'EPSG:31370' objects is effectively degraded ",
"and should not be used.\n",
"See https://inbo.github.io/n2khab/#suppressing-rgdal-warnings-about-",
"proj4string-degradation\nfor more information.")
}
56 changes: 56 additions & 0 deletions R/read_raster_runif.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#' Return the data source \code{raster_runif} as a RasterLayer
#'
#' The \code{raster_runif} data source covers Flanders and the Brussels
#' Capital Region
#' and has a resolution of 32 meters.
#' The raster cells with non-missing values match the value-cells of
#' the \code{GRTSmaster_habitats} data source (see \code{\link{read_GRTSmh}})
#' with a small buffer added.
#' Every raster cell has a random value between 0 and 1 according to the
#' uniform distribution.
#' The coordinate reference system is 'Belge 72 / Belgian Lambert 72'
#' (EPSG-code \href{https://epsg.io/31370}{31370}).
#'
#' The \code{raster_runif} data source is a GeoTIFF file (available at
#' \href{https://doi.org/10.5281/zenodo.4745984}{Zenodo}).
#'
#' The R-code for creating the \code{raster_runif} data source can be found in
#' the GitHub repository \href{https://github.com/inbo/n2khab-preprocessing/tree/ede43a4/src/generate_raster_runif}{
#' 'n2khab-preprocessing' at commit ede43a4}.
#'
#' @inheritParams read_habitatmap_stdized
#'
#' @return
#' A RasterLayer.
#'
#' @examples
#' \dontrun{
#' # This example supposes that your working directory or a directory up to 10
#' # levels above has
#' # the 'n2khab_data' folder AND that the latest version of the
#' # 'raster_runif' data source is present in the default subdirectory.
#' # In all other cases, this example won't work but at least you can consider
#' # what to do.
#' r <- read_raster_runif()
#' r
#' raster::spplot(r)
#' }
#'
#' @export
#' @importFrom assertthat
#' assert_that

read_raster_runif <-
function(file = file.path(fileman_up("n2khab_data"),
"10_raw/raster_runif/raster_runif.tif"),
version = "raster_runif_v1") {

assert_that(file.exists(file))

require_pkgs("raster")

r <- raster::raster(file)
raster::crs(r) <- "EPSG:31370"

return(r)
}
2 changes: 1 addition & 1 deletion man/read_GRTSmh_diffres.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions man/read_raster_runif.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ reference:
- read_soilmap
- read_watersurfaces
- read_watercourse_100mseg
- title: "Using the GRTSmaster data sources (raw + processed)"
- title: "Using the GRTSmaster related data sources"
contents:
- read_GRTSmh
- read_GRTSmh_base4frac
- read_GRTSmh_diffres
- read_raster_runif
- title: "Managing files and directories"
contents:
- fileman_folders
Expand Down