Learn R Programming

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

bcmaps

Version 0.18.1

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 etc. All layers are available in the BC Albers projection, which is the B.C. Government standard as sf or Spatial objects.

Layers are stored in the bcmapsdata package and loaded by this package, following the strategy recommended by Anderson and Eddelbuettel.

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 get full usage of the package, you will also need to install the bcmapsdata package, which holds all of the datasets.

Note that unlike most packages it is not necessary to actually load the bcmapsdata package (i.e., with library(bcmapsdata)) - in fact it is less likely to cause problems if you don’t.

install.packages('bcmapsdata', repos='https://bcgov.github.io/drat/')

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

#> Loading required package: sf
#> Linking to GEOS 3.8.1, GDAL 2.4.4, PROJ 7.0.0
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 or Spatial object. For example:

library(sf)

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

Alternatively, you can use the get_layer function - simply type get_layer('layer_name'), where 'layer_name' is the name of the layer of interest. The get_layer function is useful if the back-end bcmapsdata package has had a layer added to it, but there is as yet no shortcut function created in bcmaps.

library(sf)
library(dplyr)

ws <- get_layer("wsc_drainages", class = "sf")

plot(ws["SUB_SUB_DRAINAGE_AREA_NAME"], key.pos = NULL)

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)

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_discrete(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)
ggplot() +
  geom_sf(data = bec[bec$ZONE %in% c("BG", "PP"),],
          aes(fill = ZONE, col = ZONE)) +
  scale_fill_manual(values = bec_colors()) +
  scale_colour_manual(values = bec_colours())

Spatial (sp) objects

If you aren’t using the sf package and prefer the old standard sp way of doing things, set class = "sp" in either get_layer or the shortcut functions:

library("sp")
# Load watercourse data and plot with boundaries of B.C.
plot(get_layer("bc_bound", class = "sp"))
plot(watercourses_15M(class = "sp"), add = TRUE)

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:

  1. fix_geo_problems() for fixing invalid topologies in sf or Spatial objects such as orphaned holes and self-intersections
  2. transform_bc_albers() for transforming any sf or Spatial object to BC Albers projection.
  3. self_union() Union a SpatialPolygons* object with itself to remove overlaps, while retaining attributes

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.

This repository is maintained by Environmental Reporting BC. Click here for a complete list of our repositories on GitHub.

Copy Link

Version

Install

install.packages('bcmaps')

Monthly Downloads

509

Version

0.18.1

License

Apache License (== 2.0) | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andy Teucher

Last Published

April 29th, 2020

Functions in bcmaps (0.18.1)

ecoregions

British Columbia Ecoregions
get_layer

Get a B.C. spatial layer
nr_areas

British Columbia Natural Resource (NR) Areas
watercourses_5M

British Columbia watercourses at 1:5M scale
wsc_drainages

Water Survey of Canada Sub-Sub-Drainage Areas
bc_area

The size of British Columbia
nr_districts

British Columbia Natural Resource (NR) Districts
get_poly_attribute

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

Download a large data file
fix_geo_problems

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

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

Hydrologic Zone Boundaries of British Columbia
gw_aquifers

British Columbia's developed ground water aquifers
ecosections

British Columbia Ecosections
transform_bc_albers

Transform a Spatial* object to BC Albers projection
bec

British Columbia BEC Map
combine_nr_rd

Combine Northern Rockies Regional Municipality with Regional Districts
bec_colours

Biogeoclimatic Zone Colours
ecoprovinces

British Columbia Ecoprovinces
make_shortcuts

Make shortcut functions for data objects in bcmapsdata
nr_regions

British Columbia Natural Resource (NR) Regions
water_precincts

British Columbia's Water Management Precincts
municipalities

British Columbia Municipalities
regional_districts

British Columbia Regional Districts
self_union

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

British Columbia watercourses at 1:15M scale
raster_by_poly

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

British Columbia's Water Management Districts
tsa

British Columbia Timber Supply Areas and TSA Blocks
bc_bbox

Get an extent/bounding box for British Columbia
bc_bound

BC Boundary
airzones

British Columbia Air Zones
add_license_header

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

Boundary of British Columbia, provinces/states and the portion of the Pacific Ocean that borders British Columbia
available_layers

List available data layers
bcmaps

bcmaps: A data package providing various map layers for British Columbia
bc_cities

BC Major Cities Points 1:2,000,000 (Digital Baseline Mapping)
bc_bound_hres

BC Boundary - High Resolution