bcgov / bcmaps

An R package of map layers for British Columbia
http://bcgov.github.io/bcmaps/
Apache License 2.0
73 stars 17 forks source link

Add basemaps #43

Open Bevann opened 6 years ago

Bevann commented 6 years ago

A helpful addition to the package would be to have the basemaps from BCGW accessible through the package either at the different scales, or with an autoscale function if feasible.

ateucher commented 6 years ago

This would be a really nice feature. Of the basemap layers you use from the BCGW, what are the top ones you use for creating maps?

Bevann commented 6 years ago

Typically everything in the base maps auto scale, most importantly the transportation lines, major cities and water bodies/rivers. The only one I turn off is typically elevation points.

stephhazlitt commented 6 years ago

Nice idea. What data licence are the base maps distributed under?

boshek commented 4 years ago

Similar to what we are doing here #74, we could use these as basemaps: https://pub.data.gov.bc.ca/datasets/177864/tif/bcalb

boshek commented 3 years ago

For posterity just adding this as a possibility for basemaps:

library(tmap)
library(bcmaps)
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(sf)
library(raster)
#> Loading required package: sp

url <- "https://pub.data.gov.bc.ca/datasets/177864/tif/bcalb/092k/bc_092k_xc10m_bcalb.zip"
zip_path <- tempfile(fileext = ".zip")
download.file(url, destfile = zip_path)
tif_dir <- tempdir()
unzip(zip_path, exdir = tif_dir)

base <- brick(list.files(tif_dir, pattern = "tif", full.names = TRUE))
rd <- regional_districts() %>%
  st_transform(raster::crs(base)) %>%
  st_intersection(st_bbox(base) %>% st_as_sfc()) %>%
  st_intersection(bc_bound() %>% st_transform(raster::crs(base)))
#> regional_districts was updated on 2020-08-26
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries

#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries

tm_shape(base) +
  tm_rgb() +
  tm_shape(rd) +
  tm_polygons(border.col = "black", alpha = 0.2, col = "ADMIN_AREA_NAME") +
  tm_layout(legend.outside = TRUE)
#> stars object downsampled to 1122 by 891 cells. See tm_shape manual (argument raster.downsample)
#> Some legend labels were too wide. These labels have been resized to 0.62, 0.57, 0.66. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.

bevingtona commented 10 months ago

You can also add BC Gov WMS services to leaflet. No functions needed, just a good FYI and potential vignette for pretty leaflet maps for BC.

library(leaflet)
leaflet() %>%
  addWMSTiles("http://maps.gov.bc.ca/arcserver/rest/services/province/roads_wm/MapServer/tile/{z}/{y}/{x}", layers = "GRB_BSK", options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
  fitBounds(-139.01451,47.68300,-110.48408,59.99974)  

image

David-Rattray commented 9 months ago

Hi, was curious if there was any further suggestion/guidance for building basemaps? I'm aiming to create static maps in tmap along the lines of other MoH map products like https://www2.gov.bc.ca/assets/gov/data/geographic/land-use/administrative-boundaries/health-boundaries/health-boundaries-wall-map.pdf however I'm not sure what the best source for the basemap is, my searching through BC Data catalogue and looking at packages like rnaturalearth, haven't quite met my use case.

bevingtona commented 9 months ago

@David-Rattray I think if you are looking to recreate a map like the one you shared in tmap you'll need to load all the layers individually, then spend a good amount of time setting up the layout with the nested inset maps. See below as a bare bones example.

It you are interested in having WMS/WMTS layers in static maps... that may be a bit trickier!.. maybe using something like: https://github.com/hypertidy/ceramic ?

library(bcmaps)
#> Loading required package: sf
#> Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
#> Support for Spatial objects (`sp`) was removed in {bcmaps} v2.0.0. Please use `sf` objects with {bcmaps}.
library(tmap)
#> Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
#> remotes::install_github('r-tmap/tmap')

bc_neighbours <- bcmaps::bc_neighbours()
#> bc_neighbours was updated on 2024-01-30
bc_cities <- bcmaps::bc_cities()
watercourses_5M <- bcmaps::watercourses_5M()

tm_shape(bc_neighbours) + tm_fill(col = "iso_a2", palette = c("grey90","steelblue1","grey80"), legend.show = F) + tm_borders() + 
  tm_shape(bc_cities) + tm_dots(size = 0.3, shape = 1) + 
  tm_shape(watercourses_5M) + tm_lines(col = "steelblue")

Created on 2024-01-30 with reprex v2.0.2

stephhazlitt commented 9 months ago

Thanks for your comment @David-Rattray. Are you looking for guidance for wayfinding of basemap data or accessing basemap data with bcmaps? At this time sourcing basemap data with bcmaps (or bcdata) is not possible. If I understand things correctly, there are BC Data Catalogue records for various basemaps, but the data itself are not available through the Web Feature Service, and instead by custom order (but see basemap data here). So as @bevingtona mentioned, you would need to download the data and then go from there. And agreed, making insets is finicky, but doable with patience---this blog post might help https://upgo.lab.mcgill.ca/2019/12/13/making-beautiful-maps/.

David-Rattray commented 9 months ago

@bevingtona @stephhazlitt thank you both for the quick responses and advice! The example I shared maybe is a bit more focused on insets than what I will need to do. The part of it I really want to create is that base terrain layer, then layer on the boundaries of various health geographies etc. Thanks for the directions towards the data catalogue, I'll pursue that and hopefully have a positive update in the near future.