Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/massbays-tech/MassWateR int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
fawda123 committed Oct 20, 2024
2 parents b054d34 + 63df8b6 commit 340cd87
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Imports:
ggspatial,
httr,
lubridate,
prettymapr,
raster,
maptiles,
RColorBrewer,
rmarkdown,
readxl,
sf,
tidyr,
tidyterra,
tibble,
units,
writexl
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export(utilMWRvaluerange)
export(utilMWRyscale)
import(RColorBrewer)
import(dplyr)
import(prettymapr)
import(tidyr)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
Expand Down
30 changes: 16 additions & 14 deletions R/anlzMWRmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @param zoom numeric indicating resolution of the base map, see details
#' @param addwater character string as \code{"low"}, \code{"medium"} (default), \code{"high"}, or \code{NULL} (to suppress) to include water features with varying detail from the National Hydrography dataset, see details
#' @param watercol character string of color for water objects if \code{addwater} is not \code{NULL}
#' @param maptype character string as \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, \code{"hotstyle"}, or \code{NULL} (to suppress, default) indicating the basemap type, see details
#' @param maptype character string indicating the basemap type, see details
#' @param buffdist numeric for buffer around the bounding box for the selected sites in kilometers, see details
#' @param scaledist character string indicating distance unit for the scale bar, \code{"km"} or \code{"mi"}
#' @param northloc character string indicating location of the north arrow, see details
Expand All @@ -29,8 +29,6 @@
#' @param runchk logical to run data checks with \code{\link{checkMWRresults}}, \code{\link{checkMWRacc}}, or \code{\link{checkMWRsites}}, applies only if \code{res}, \code{acc}, or \code{sit} are file paths
#' @param warn logical to return warnings to the console (default)
#'
#' @import prettymapr
#'
#' @return A \code{\link[ggplot2]{ggplot}} object that can be further modified.
#' @export
#'
Expand All @@ -45,7 +43,7 @@
#'
#' Using \code{addwater = "medium"} (default) will include lines and polygons of natural water bodies defined using the National Hydrography Dataset (NHD). The level of detail can be changed to low or high using \code{addwater = "low"} or \code{addwater = "high"}, respectively. Use \code{addwater = NULL} to not show any water features.
#'
#' A base map can be plotted using the \code{maptype} argument and is obtained from the \code{\link[ggspatial]{annotation_map_tile}} function of ggspatial. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, or \code{"hotstyle"}. Use \code{maptype = NULL} to suppress the base map.
#' A base map can be plotted using the \code{maptype} argument. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"OpenStreetMap"}, \code{"OpenStreetMap.DE"}, \code{"OpenStreetMap.France"}, \code{"OpenStreetMap.HOT"}, \code{"OpenTopoMap"}, \code{"Esri.WorldStreetMap"}, \code{"Esri.DeLorme"}, \code{"Esri.WorldTopoMap"}, \code{"Esri.WorldImagery"}, \code{"Esri.WorldTerrain"}, \code{"Esri.WorldShadedRelief"}, \code{"Esri.OceanBasemap"}, \code{"Esri.NatGeoWorldMap"}, \code{"Esri.WorldGrayCanvas"}, \code{"CartoDB.Positron"}, \code{"CartoDB.PositronNoLabels"}, \code{"CartoDB.PositronOnlyLabels"}, \code{"CartoDB.DarkMatter"}, \code{"CartoDB.DarkMatterNoLabels"}, \code{"CartoDB.DarkMatterOnlyLabels"}, \code{"CartoDB.Voyager"}, \code{"CartoDB.VoyagerNoLabels"}, or \code{"CartoDB.VoyagerOnlyLabels"}. Use \code{maptype = NULL} to suppress the base map.
#'
#' The area around the summarized points can be increased or decreased using the \code{buffdist} argument. This creates a buffered area around the bounding box for the points, where the units are kilometers.
#'
Expand Down Expand Up @@ -139,31 +137,35 @@ anlzMWRmap<- function(res = NULL, param, acc = NULL, sit = NULL, fset = NULL, si
sf::st_as_sfc() %>%
sf::st_buffer(dist = units::set_units(buffdist, kilometer)) %>%
sf::st_transform(crs = 4326) %>%
sf::st_bbox() %>%
unname
sf::st_bbox()
if(nrow(tomap) == 1)
dat_ext <- tomap %>%
sf::st_as_sfc() %>%
sf::st_buffer(dist = units::set_units(buffdist, kilometer)) %>%
sf::st_transform(crs = 4326) %>%
sf::st_bbox() %>%
unname
sf::st_bbox()

ylab <- unique(resdat$`Result Unit`)
ttl <- utilMWRtitle(param = param, accdat = accdat, sumfun = sumfun, site = site, dtrng = dtrng, locgroup = locgroup, resultatt = resultatt)

m <- ggplot2::ggplot()

if(!is.null(maptype)){

maptype <- match.arg(maptype, c( 'cartolight', 'cartodark', 'osm', 'hotstyle'))

# this is only to satisfy raster in imports, does nothing
# do not import all of raster becaus of namespace conflicts
tmp <- raster::as.data.frame(x = NULL)
maptype <- match.arg(maptype, c("OpenStreetMap", "OpenStreetMap.DE", "OpenStreetMap.France",
"OpenStreetMap.HOT", "OpenTopoMap",
"Esri.WorldStreetMap", "Esri.DeLorme", "Esri.WorldTopoMap",
"Esri.WorldImagery", "Esri.WorldTerrain", "Esri.WorldShadedRelief",
"Esri.OceanBasemap", "Esri.NatGeoWorldMap", "Esri.WorldGrayCanvas",
"CartoDB.Positron", "CartoDB.PositronNoLabels",
"CartoDB.PositronOnlyLabels", "CartoDB.DarkMatter",
"CartoDB.DarkMatterNoLabels", "CartoDB.DarkMatterOnlyLabels",
"CartoDB.Voyager", "CartoDB.VoyagerNoLabels", "CartoDB.VoyagerOnlyLabels"))

tls <- maptiles::get_tiles(dat_ext, provider = maptype, zoom = zoom, )

m <- m +
ggspatial::annotation_map_tile(zoom = zoom, quiet = TRUE, progress = "none", type = maptype, cachedir = system.file("rosm.cache", package = "ggspatial"))
tidyterra::geom_spatraster_rgb(data = tls, maxcell = 1e8)

}

Expand Down
4 changes: 2 additions & 2 deletions man/anlzMWRmap.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-anlzMWRmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("Checking output format", {

test_that("Checking output format, one site", {
skip_on_cran()
result <- anlzMWRmap(res = resdat, param = 'DO', acc = accdat, sit = sitdat, warn = FALSE, site = 'ABT-026', addwater = NULL, maptype = 'osm', zoom = 5)
result <- anlzMWRmap(res = resdat, param = 'DO', acc = accdat, sit = sitdat, warn = FALSE, site = 'ABT-026', addwater = NULL, maptype = 'CartoDB.Positron', zoom = 5)
expect_s3_class(result, 'ggplot')
})

Expand Down
10 changes: 5 additions & 5 deletions vignettes/analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,18 @@ The buffered distance around the points can be increased using the `buffdist` ar
anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, buffdist = 20, warn = F)
```

A base map can be included as well using the `maptype` argument. Options include `"cartolight"`, `"cartodark"`, `"osm"`, or `"hotstyle"`. The `zoom` argument can be helpful when using a basemap. The default `zoom` argument is set to 11 and decreasing the number will download a base map with lower resolution. This can decrease map processing times for large areas.
A base map can be included as well using the `maptype` argument. Options include `"OpenStreetMap"`, `"OpenStreetMap.DE"`, `"OpenStreetMap.France"`, `"OpenStreetMap.HOT"`, `"OpenTopoMap"`, `"Esri.WorldStreetMap"`, `"Esri.DeLorme"`, `"Esri.WorldTopoMap"`, `"Esri.WorldImagery"`, `"Esri.WorldTerrain"`, `"Esri.WorldShadedRelief"`, `"Esri.OceanBasemap"`, `"Esri.NatGeoWorldMap"`, `"Esri.WorldGrayCanvas"`, `"CartoDB.Positron"`, `"CartoDB.PositronNoLabels"`, `"CartoDB.PositronOnlyLabels"`, `"CartoDB.DarkMatter"`, `"CartoDB.DarkMatterNoLabels"`, `"CartoDB.DarkMatterOnlyLabels"`, `"CartoDB.Voyager"`, `"CartoDB.VoyagerNoLabels"`, or `"CartoDB.VoyagerOnlyLabels"`. The `zoom` argument can be helpful when using a basemap. The default `zoom` argument is set to 11 and decreasing the number will download a base map with lower resolution. This can decrease map processing times for large areas.

A `"cartolight"` base map:
A `"CartoDB.Positron"` base map:

```{r, fig.height = 6, fig.width = 6}
anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "cartolight", warn = F, addwater = NULL)
anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "CartoDB.Positron", warn = F, addwater = NULL)
```

A `"osm"` base map:
A `"Esri.WorldImagery"` base map:

```{r, fig.height = 6, fig.width = 6}
anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "osm", warn = F, addwater = NULL)
anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "Esri.WorldImagery", warn = F, addwater = NULL)
```

A map with no base map or water bodies:
Expand Down

0 comments on commit 340cd87

Please sign in to comment.