From 9260f44094b053a5b488f141c8e7e2a279f5a5ef Mon Sep 17 00:00:00 2001 From: Jason Fisher <jfisher@usgs.gov> Date: Wed, 22 Nov 2023 20:55:18 -0800 Subject: [PATCH 1/3] fix albers in metadata --- inst/extdata/metadata.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inst/extdata/metadata.json b/inst/extdata/metadata.json index 44d58d21..a0bffa3f 100644 --- a/inst/extdata/metadata.json +++ b/inst/extdata/metadata.json @@ -111,8 +111,9 @@ "planar": { "mapproj": { "mapprojn": ["Albers Conical Equal Area"], - "transmer": { - "sfctrmer": ["1"], + "albers": { + "stdparll": ["42.833333"], + "stdparll": ["44.166667"], "longcm": ["-113"], "latprjo": ["41.5"], "feast": ["200000"], -- GitLab From 84187841e5cedda68422d394f7aabcfa9cb2473b Mon Sep 17 00:00:00 2001 From: Jason Fisher <jfisher@usgs.gov> Date: Wed, 22 Nov 2023 21:01:09 -0800 Subject: [PATCH 2/3] minor change --- inst/extdata/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/extdata/metadata.json b/inst/extdata/metadata.json index a0bffa3f..a3744feb 100644 --- a/inst/extdata/metadata.json +++ b/inst/extdata/metadata.json @@ -113,7 +113,7 @@ "mapprojn": ["Albers Conical Equal Area"], "albers": { "stdparll": ["42.833333"], - "stdparll": ["44.166667"], + "stdparll": ["44.166666"], "longcm": ["-113"], "latprjo": ["41.5"], "feast": ["200000"], -- GitLab From 40eb400bac73ddd50bcc6ea01f4f65b74a02a98d Mon Sep 17 00:00:00 2001 From: Jason Fisher <jfisher@usgs.gov> Date: Fri, 24 Nov 2023 00:30:00 -0800 Subject: [PATCH 3/3] tidy code and add topo metadata --- R/make_data_release.R | 73 ++++++++++++++++++++++++++----------------- R/topo.R | 12 +++---- man/topo.Rd | 12 +++---- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/R/make_data_release.R b/R/make_data_release.R index bb58364f..437e43df 100644 --- a/R/make_data_release.R +++ b/R/make_data_release.R @@ -88,7 +88,7 @@ make_data_release <- function(metadata, desc <- c(rd$description, rd$references) |> paste(collapse = "\n\n") # make dataset source - src <- if (is.null(rd$source)) "Producer defined" else rd$source + src <- if (is.null(rd$source)) "Producer defined." else rd$source # add dataset description detailed$enttyp <- list( @@ -104,6 +104,9 @@ make_data_release <- function(metadata, # get information from dataset object text <- paste(package, ds_names[i], sep = "::") ds <- parse(text = text) |> eval() + if (inherits(ds, "PackedSpatRaster")) { + ds <- terra::unwrap(ds) + } ds <- try(as.data.frame(ds), silent = TRUE) if (is.data.frame(ds)) { if (!checkmate::test_subset(d$name, choices = colnames(ds))) { @@ -111,31 +114,14 @@ make_data_release <- function(metadata, } ds <- ds[, d$name, drop = FALSE] - # add no-data values - d$no_va <- lapply(ds, function(x) { - if (anyNA(x)) { - list( - "edomv" = list("NA"), - "edomvd" = list("No Data"), - "edomvds" = list("Producer defined") - ) - } else { - NULL - } - }) |> I() + # add no-data flag + d$is_na <- vapply(ds, FUN = anyNA, FUN.VALUE = logical(1)) - # add range of values + # add data range d$range <- lapply(ds, function(x) { if (checkmate::test_double(x, all.missing = FALSE)) { ran <- range(x, na.rm = TRUE, finite = TRUE) - list( - "rdommin" = list( - format(ran[1], scientific = FALSE) - ), - "rdommax" = list( - format(ran[2], scientific = FALSE) - ) - ) + vapply(ran, FUN = format, FUN.VALUE = character(1), scientific = FALSE) } else { NULL } @@ -147,15 +133,41 @@ make_data_release <- function(metadata, l <- list() l$attrlabl <- list(x["name"]) l$attrdef <- list(x["value"]) - l$attrdefs <- list("Producer defined") - if (!is.null(x$no_va)) { - l <- c(l, list("attrdomv" = list("edom" = x$no_va))) + l$attrdefs <- list("Producer defined.") + + # add no-data value + if (x$is_na) { + l <- c(l, list( + "attrdomv" = list( + "edom" = list( + "edomv" = list("NA"), + "edomvd" = list("No Data"), + "edomvds" = list("Producer defined.") + ) + ) + )) } - if (is.null(x$range)) { - l <- c(l, list("attrdomv" = list("udom" = list("See attribute definition.")))) + + # add numeric-data type + if (!is.null(x$range)) { + l <- c(l, list( + "attrdomv" = list( + "rdom" = list( + "rdommin" = list(x$range[1]), + "rdommax" = list(x$range[2]) + ) + ) + )) + + # add unknown-data type } else { - l <- c(l, list("attrdomv" = list("rdom" = x$range))) + l <- c(l, list( + "attrdomv" = list( + "udom" = list("See attribute definition.") + ) + )) } + l }) names(attrs) <- rep("attr", nrow(d)) @@ -189,7 +201,10 @@ make_data_release <- function(metadata, # add bounding coordinates if (!is.null(bounding)) { - l <- sf::st_transform(bounding, crs = "EPSG:4326") |> sf::st_bbox() |> as.numeric() |> lapply(FUN = list) + l <- sf::st_transform(bounding, crs = "EPSG:4326") |> + sf::st_bbox() |> + as.numeric() |> + lapply(FUN = list) names(l) <- c("westbc", "southbc", "eastbc", "northbc") l <- l[c(1, 3, 4, 2)] metadata[[1]]$idinfo$spdom$bounding <- l diff --git a/R/topo.R b/R/topo.R index 17db715e..0d208546 100644 --- a/R/topo.R +++ b/R/topo.R @@ -1,13 +1,13 @@ #' Land-Surface Topography #' -#' Raster data describing the land-surface topography +#' Raster layers describing the land-surface topography #' in the vicinity of Idaho National Laboratory, eastern Idaho. #' -#' @format A compressed collection of [`SpatRaster`][terra::SpatRaster]-class objects. -#' Contains an `elevation` layer describing the land-surface elevations in feet above the -#' North American Vertical Datum of 1988 (NAVD 88). -#' And a `hillshade` layer describing the shaded relief calculated from -#' the slope and aspect of land-surface elevations. +#' @format A compressed collection of [`SpatRaster`][terra::SpatRaster]-class objects with layers: +#' \describe{ +#' \item{`elevation`}{Land-surface elevations in feet above the North American Vertical Datum of 1988 (NAVD 88).} +#' \item{`hillshade`}{Shaded relief calculated from the slope and aspect of land-surface elevations.} +#' } #' The spatial grid is composed of 900 rows and 900 columns, #' and has cell sizes that are constant at 100 meters by 100 meters. #' See [`projection`] dataset for coordinate reference system information. diff --git a/man/topo.Rd b/man/topo.Rd index eda97917..b2693810 100644 --- a/man/topo.Rd +++ b/man/topo.Rd @@ -5,11 +5,11 @@ \alias{topo} \title{Land-Surface Topography} \format{ -A compressed collection of \code{\link[terra:SpatRaster-class]{SpatRaster}}-class objects. -Contains an \code{elevation} layer describing the land-surface elevations in feet above the -North American Vertical Datum of 1988 (NAVD 88). -And a \code{hillshade} layer describing the shaded relief calculated from -the slope and aspect of land-surface elevations. +A compressed collection of \code{\link[terra:SpatRaster-class]{SpatRaster}}-class objects with layers: +\describe{ +\item{\code{elevation}}{Land-surface elevations in feet above the North American Vertical Datum of 1988 (NAVD 88).} +\item{\code{hillshade}}{Shaded relief calculated from the slope and aspect of land-surface elevations.} +} The spatial grid is composed of 900 rows and 900 columns, and has cell sizes that are constant at 100 meters by 100 meters. See \code{\link{projection}} dataset for coordinate reference system information. @@ -31,7 +31,7 @@ The elevation data set was converted into a hillshade dataset. topo } \description{ -Raster data describing the land-surface topography +Raster layers describing the land-surface topography in the vicinity of Idaho National Laboratory, eastern Idaho. } \examples{ -- GitLab