bcgov / bcgov-r-geo-workshop

Some lessons & resources supporting an R geospatial workshop & hackathon
Other
26 stars 10 forks source link

Add custom WMS service as a basemap for a ggplot2 #11

Closed bevingtona closed 4 years ago

bevingtona commented 4 years ago

Don't know how to do this... Perhaps emulate the code from ggspatial::annotation_map_tile() that allows Open Street Map to be your basemap.

boshek commented 4 years ago

I also do not know how to do this. Bashing away did make me think of using bcdata somehow. It is pretty slick what you can accomplish so readily. So just adding some code here that integrates the two at a minimal level:

library(ggspatial)
#> Loading required package: ggplot2
library(bcdata)
#> 
#> Attaching package: 'bcdata'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(ggplot2)

parks <- bcdc_query_geodata('national-parks-of-canada-within-british-columbia') %>% 
  filter(ENGLISH_NAME == "Southern Gulf Islands National Park Reserve of Canada") %>% 
  collect()
#> Warning: It is advised to use the permanent id ('88e61a14-19a0-46ab-bdae-f68401d3d0fb') rather than the name of the record ('national-parks-of-canada-within-british-columbia') to guard against future name changes.

ggplot() +
  annotation_map_tile(zoom = 13) +
  geom_sf(data = parks, fill = "green", alpha = 0.5, col = "grey50")

Created on 2019-10-29 by the reprex package (v0.3.0)