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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses #42 and #63 -- adds pkgdown site and reorgs readme content #125

Merged
merged 33 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
acd2e76
fix incorrect sentence
stephhazlitt Jun 2, 2023
5b9336b
fix object name
stephhazlitt Jun 2, 2023
29973cd
fix overlay plot
stephhazlitt Jun 3, 2023
ab7c0d8
use pkgdown
stephhazlitt Jun 3, 2023
c229874
update points vig png
stephhazlitt Jun 3, 2023
a91a8f7
move content to bcmaps vig
stephhazlitt Jun 3, 2023
2c664bc
trim readme
stephhazlitt Jun 3, 2023
6835bdf
update paths to figs
stephhazlitt Jun 3, 2023
ad97eeb
precompile vignettes
stephhazlitt Jun 3, 2023
a501760
mv figs to man/
stephhazlitt Jun 3, 2023
2da8880
update pkgdown folder
stephhazlitt Jun 3, 2023
b4a4ce0
rm plot args
stephhazlitt Jun 3, 2023
5b2fc27
add interactive precompile code
stephhazlitt Jun 3, 2023
2ab14ba
align vignette title
stephhazlitt Jun 3, 2023
24e786b
precompile
stephhazlitt Jun 3, 2023
bb7adba
Update vignettes/add_points.Rmd.orig
stephhazlitt Jun 3, 2023
28e0af7
Update vignettes/bcmaps.Rmd.orig
stephhazlitt Jun 3, 2023
bf0f07f
Update vignettes/bcmaps.Rmd.orig
stephhazlitt Jun 3, 2023
b6e52e2
Update README.Rmd
stephhazlitt Jun 3, 2023
9eeba09
add dev auto mode
stephhazlitt Jun 3, 2023
8d1ac0c
render text update
stephhazlitt Jun 3, 2023
8936485
implement #124
stephhazlitt Jun 3, 2023
91b7cee
precompile
stephhazlitt Jun 3, 2023
58d2ac7
update news
stephhazlitt Jun 3, 2023
af39df5
Merge branch 'main' into issue-42-63
stephhazlitt Jun 3, 2023
03ad711
render readme uhhg
stephhazlitt Jun 3, 2023
8a20d53
better news update
stephhazlitt Jun 4, 2023
10096f4
replace databc w/ bcdc
stephhazlitt Jun 4, 2023
923641b
edit bc bound source text
stephhazlitt Jun 4, 2023
602a890
rm Spatial+ggplot refs
stephhazlitt Jun 4, 2023
d199416
Update vignettes/bcmaps.Rmd.orig
stephhazlitt Jun 4, 2023
c2c48a0
use reset = FALSE
stephhazlitt Jun 4, 2023
6d4533f
precompile
stephhazlitt Jun 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ CONTRIBUTING.md
^data-raw$
^revdep$
^CRAN-SUBMISSION$
^_pkgdown\.yml$
^docs$
^pkgdown$
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 馃殌
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ data-raw/prov_territories_statscan/gpr_000b11a_e.shx
.*.Rnb.cached
*.zip
*.pdf
docs
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Authors@R:
role = "cph"))
Description: Various layers of B.C., including administrative boundaries, natural resource management boundaries, census boundaries etc. All layers are available in BC Albers (<https://spatialreference.org/ref/epsg/nad83-bc-albers/>) equal-area projection, which is the B.C. government standard. The layers are sourced from the British Columbia and Canadian government under open licenses, including B.C. Data Catalogue (<https://data.gov.bc.ca>), the Government of Canada Open Data Portal (<https://open.canada.ca/en/open-data>), and Statistics Canada (<https://www.statcan.gc.ca/eng/reference/licence>).
License: Apache License (== 2.0) | file LICENSE
URL: https://github.com/bcgov/bcmaps
URL: https://github.com/bcgov/bcmaps,
http://bcgov.github.io/bcmaps/
BugReports: https://github.com/bcgov/bcmaps/issues
Depends:
sf (>= 0.9),
Expand Down
118 changes: 11 additions & 107 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message=FALSE,
fig.path = "tools/readme/",
fig.path = "man/figures/",
dpi = 150
)

ggplot2::theme_set(ggplot2::theme_minimal())
```

# bcmaps <img src="tools/readme/bcmaps-sticker.png" height="139" align="right"/>
# bcmaps <img src="man/figures/logo.png" height="139" align="right"/>

<!-- badges: start -->
[![img](https://img.shields.io/badge/Lifecycle-Stable-97ca00)](https://github.com/bcgov/repomountie/blob/8b2ebdc9756819625a56f7a426c29f99b777ab1d/doc/state-badges.md)
Expand All @@ -28,18 +28,13 @@ ggplot2::theme_set(ggplot2::theme_minimal())
<!-- badges: end -->



## Overview

An [R](https://www.r-project.org) package of spatial map layers for British Columbia.

## Features

Provides access to various spatial layers of British Columbia, such as
`bcmaps` 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](https://spatialreference.org/ref/epsg/nad83-bc-albers/) projection, which is the B.C. Government standard.

Most layers are assessed directly from the [B.C. Data Catalogue](https://catalogue.data.gov.bc.ca/) using the [bcdata](https://github.com/bcgov/bcdata) R package. See each layers individual help file for more detail.
Most layers are assessed directly from the [B.C. Data Catalogue](https://catalogue.data.gov.bc.ca/) using the [bcdata](https://github.com/bcgov/bcdata) R package under the hood. See each layers individual help file for more detail.
stephhazlitt marked this conversation as resolved.
Show resolved Hide resolved


> _**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.
Expand All @@ -60,7 +55,7 @@ install.packages("remotes")
remotes::install_github("bcgov/bcmaps")
```

## Usage
## Quick Start

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

Expand All @@ -73,10 +68,8 @@ 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:
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.

```{r}
library(sf)
Expand All @@ -85,102 +78,13 @@ bc <- bc_bound()
plot(st_geometry(bc))
```

### Simple Features objects

By default, all layers are returned as [`sf` spatial objects](https://cran.r-project.org/package=sf):

```{r plot-maps, fig.height=5, warning=FALSE}
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:

```{r cded}
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](https://ggplot2.tidyverse.org/) package to plot maps in R using `geom_sf`:

```{r bc_neighbours}
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:

```{r include=FALSE}
bec <- bec(ask = FALSE)
```

```{r bec, message=FALSE}
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:

```{r, eval=FALSE}
ep <- ecoprovinces(force = TRUE)
```

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

```{r, eval=FALSE}
delete_cache('ecoprovinces')
ep <- ecoprovinces()
```


### Vignettes

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

### Utility Functions
## Vignettes

The package also contains a couple of handy utility functions:
[Getting Started with `bcmaps`](https://bcgov.github.io/bcmaps/articles/bcmaps.html)
[Working with bcmaps layers with point location data](https://bcgov.github.io/bcmaps/articles/add_points.html)

- `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](https://epsg.io/3005) projection
You can also view vignettes by typing `browseVignettes("bcmaps")` in your R session after you install `bcmaps`.


## Getting Help or Reporting an Issue
Expand Down
Loading
Loading