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 basemaps #43

Open
Bevann opened this issue Nov 7, 2018 · 10 comments
Open

Add basemaps #43

Bevann opened this issue Nov 7, 2018 · 10 comments

Comments

@Bevann
Copy link

Bevann commented Nov 7, 2018

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
Copy link
Collaborator

ateucher commented Nov 7, 2018

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
Copy link
Author

Bevann commented Nov 7, 2018

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
Copy link
Member

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

@boshek
Copy link
Collaborator

boshek commented Nov 17, 2020

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
Copy link
Collaborator

boshek commented Dec 10, 2020

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
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator

@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
Copy link
Member

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
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants