library(rgdal)
#> Loading required package: sp
#> rgdal: version: 1.4-3, (SVN revision 828)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
#> Path to GDAL shared files: /Users/ateucher/Rlibrary/rgdal/gdal
#> GDAL binary built with GEOS: FALSE
#> Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
#> Path to PROJ.4 shared files: /Users/ateucher/Rlibrary/rgdal/proj
#> Linking to sp version: 1.3-1
library(raster)
library(glue)
#>
#> Attaching package: 'glue'
#> The following object is masked from 'package:raster':
#>
#> trim
url <- "https://hectaresbc.org/cgi-bin/mapserv?map=../../habc_data/mapserver/habc.map&service=WMS&version=1.1.0&request=GetMap&layers=adminunits_forestdistrict&bbox={bbox[1]}%2C{bbox[2]}%2C{bbox[3]}%2C{bbox[4]}&width={width}&height={height}&srs=EPSG%3A3005&format=image/gtiff"
bbox <- c(273875.663, 362346.895, 1870571.76, 1735670.856)
ar <- (bbox[3] - bbox[1]) / (bbox[4] - bbox[2])
height = 2000
width <- ar * height
tiff <- tempfile(fileext = ".tiff")
download.file(glue(url), destfile = tiff)
myrast <- raster(tiff)
plot(myrast)
Created on 2019-04-15 by the reprex package (v0.2.1)