Learn R Programming

⚠️There's a newer version (2.2.1) of this package.Take me there.

bcmaps

Overview

An R package of spatial map layers for British Columbia.

Features

Provides access to various spatial layers of British Columbia, such as administrative boundaries, natural resource management boundaries, watercourses, census boundaries, etc. All layers are available as sf objects in the BC Albers projection, which is the B.C. Government standard.

Most layers are assessed directly from the B.C. Data Catalogue using the bcdata R package. See each layers individual help file for more detail.

IMPORTANT NOTE Support for Spatial objects (sp) is deprecated in {bcmaps} v1.2.0, and will be removed in Summer 2023. Please use sf objects with {bcmaps}. A discussion on the evolution of the spatial software stack in R can be found here: https://r-spatial.org/r/2022/04/12/evolution.html.

Installation

You can install bcmaps from CRAN:

install.packages("bcmaps")

To install the development version of the bcmaps package, you need to install the remotes package then the bcmaps package.

install.packages("remotes")
remotes::install_github("bcgov/bcmaps")

Usage

To see the layers that are available, run the available_layers() function:

library(bcmaps)
available_layers()

Most layers are accessible by a shortcut function by the same name as the object. Then you can use the data as you would any sf object. The first time you run try to access a layer, you will be prompted for permission to download that layer to your hard drive. Subsequently that layer is available locally for easy future access. For example:

library(sf)

bc <- bc_bound()
plot(st_geometry(bc))

Simple Features objects

By default, all layers are returned as sf spatial objects:

library(bcmaps)
library(sf)

# Load and plot the boundaries of B.C.

bc <- bc_bound()
plot(st_geometry(bc))

## Next load the Regional Districts data, then extract and plot the Kootenays
rd <- regional_districts()
kootenays <- rd[rd$ADMIN_AREA_NAME == "Regional District of Central Kootenay", ]
plot(st_geometry(kootenays), col = "lightseagreen", add = TRUE)

Digital Elevation Model for British Columbia 1:250,000

The cded_raster and cded_stars functions return the 1:250,000 digital elevation model for British Columbia bounded by some area of interest. Here we are retrieving the area bounded by the Logan Lake census subdivision:

library(raster)

aoi <- census_subdivision()[census_subdivision()$CENSUS_SUBDIVISION_NAME == "Logan Lake", ]
aoi_raster <- cded_raster(aoi)
plot(aoi_raster)

It’s a beautiful day in the neighbourhood

A handy layer for creating maps for display is the bc_neighbours layer, accessible with the function by the same name. This example also illustrates using the popular ggplot2 package to plot maps in R using geom_sf:

library(ggplot2)
ggplot() + 
  geom_sf(data = bc_neighbours(), mapping = aes(fill = name)) + 
  geom_sf(data = bc_cities()) +
  coord_sf(datum = NA) +
  scale_fill_viridis_d(name = "Jurisdiction") +
  theme_minimal()

Biogeoclimatic Zones

As of version 0.15.0 the B.C. BEC (Biogeoclimatic Ecosystem Classification) map is available via the bec() function, and an accompanying function bec_colours() function to colour it:

bec <- bec()
library(ggplot2)
bec_sub <- bec[bec$ZONE %in% c("BG", "PP"),]
ggplot() +
  geom_sf(data = bec_sub,
          aes(fill = ZONE, col = ZONE)) +
  scale_fill_manual(values = bec_colors()) +
  scale_colour_manual(values = bec_colours())

Updating layers

When you first call a layer function bcmaps will remind you when that layer was last updated in your cache with a message. For a number of reasons, it might be necessary to get a fresh layer in your bcmaps cache. The easiest way to update is to use the force argument:

ep <- ecoprovinces(force = TRUE)

Another option is to actively manage your cache by deleting the old layer and calling the function again:

delete_cache('ecoprovinces')
ep <- ecoprovinces()

Vignettes

After installing the package you can view vignettes by typing browseVignettes("bcmaps") in your R session.

Utility Functions

The package also contains a couple of handy utility functions:

  • fix_geo_problems() for fixing invalid topologies in sf objects such as orphaned holes and self-intersections
  • transform_bc_albers() for transforming any sf object to BC Albers projection

Getting Help or Reporting an Issue

To report bugs/issues/feature requests, please file an issue.

How to Contribute

Pull requests of new B.C. layers are welcome. If you would like to contribute to the package, please see our CONTRIBUTING guidelines.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Source Data

The source datasets used in this package come from various sources under open licences, including DataBC (Open Government Licence - British Columbia) and Statistics Canada (Statistics Canada Open Licence Agreement). See the data-raw folder for details on each source dataset.

Licence

# Copyright 2017 Province of British Columbia
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

Copy Link

Version

Install

install.packages('bcmaps')

Monthly Downloads

509

Version

1.2.0

License

Apache License (== 2.0) | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andy Teucher

Last Published

April 11th, 2023

Functions in bcmaps (1.2.0)

fix_geo_problems

Check and fix polygons that self-intersect, and sometimes can fix orphan holes
census_tract

Current Census Tract Boundaries
ecoprovinces

British Columbia Ecoprovinces
mapsheets_50K

NTS 50K Grid - Digital Baseline Mapping at 1:50,000 (NTS)
municipalities

British Columbia Municipalities
delete_cache

View and delete cached files
get_poly_attribute

Get or calculate the attribute of a list-column containing nested dataframes.
hydrozones

Hydrologic Zone Boundaries of British Columbia
health_lha

Local Health Area Boundaries
get_layer

Get a B.C. spatial layer
mapsheets_250K

NTS 250K Grid - Digital Baseline Mapping at 1:250,000 (NTS)
bec_colours

Biogeoclimatic Zone Colours
raster_by_poly

Overlay a SpatialPolygonsDataFrame or sf polygons layer on a raster layer and clip the raster to each polygon. Optionally done in parallel
make_shortcuts

Make shortcut functions for data objects in bcmaps from B.C. Data Catalogue
regional_districts

British Columbia Regional Districts
self_union

Union a SpatialPolygons* object with itself to remove overlaps, while retaining attributes
ecoregions

British Columbia Ecoregions
nr_regions

British Columbia Natural Resource (NR) Regions
ecosections

British Columbia Ecosections
vrt_files

List the files that a vrt is built on
tsa

British Columbia Timber Supply Areas and TSA Blocks
health_ha

Health Authority Boundaries
health_hsda

Health Service Delivery Area Boundaries
water_districts

British Columbia's Water Management Districts
fsa

British Columbia Forward Sortation Areas
summarize_raster_list

Summarize a list of rasters into a list of numeric vectors
vrt_info

Get metadata about a .vrt file
transform_bc_albers

Transform a Spatial* object to BC Albers projection
water_precincts

British Columbia's Water Management Precincts
watercourses_15M

British Columbia watercourses at 1:15M scale
combine_nr_rd

Combine Northern Rockies Regional Municipality with Regional Districts
health_chsa

Community Health Service Areas - CHSA
nr_areas

British Columbia Natural Resource (NR) Areas
wsc_drainages

Water Survey of Canada Sub-Sub-Drainage Areas
watercourses_5M

British Columbia watercourses at 1:5M scale
gw_aquifers

British Columbia's developed ground water aquifers
nr_districts

British Columbia Natural Resource (NR) Districts
available_layers

List available data layers
add_license_header

Add the boilerplate Apache header to the top of a source code file
bc_bound

BC Boundary
bc_bbox

Get an extent/bounding box for British Columbia
bc_bound_hres

BC Boundary - High Resolution
airzones

British Columbia Air Zones
bc_area

The size of British Columbia
bc_neighbours

Boundary of British Columbia, provinces/states and the portion of the Pacific Ocean that borders British Columbia
bcmaps-package

bcmaps: Map Layers and Spatial Utilities for British Columbia
bc_cities

BC Major Cities Points
cded_stars

Get Canadian Digital Elevation Model (CDED) as a stars object
cded

Canadian Digital Elevation Model (CDED)
census_economic

Current Census Economic Region Boundaries
census_metropolitan_area

Current Census Metropolitan Areas
bec

British Columbia BEC Map
census_division

Current Census Division Boundaries
cded_raster

Get Canadian Digital Elevation Model (CDED) as a raster object
census_dissemination_area

Current Census Dissemination Areas
census_subdivision

Current Census Subdivision Boundaries