Giter Club home page Giter Club logo

bcmaps's Introduction

bcmaps

img License R build status CRAN_Status_Badge CRAN Downloads

An R package of spatial map layers for British Columbia.

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 projection, which is the B.C. Government standard.

Most layers are accessed directly from the B.C. Data Catalogue using the bcdata R package under the hood. See each layer’s individual help file for more detail.

IMPORTANT NOTE Support for Spatial objects (sp) was removed in {bcmaps} v1.3.0. 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")

Quick Start

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.

library(sf)

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

A map of the outline of British Columbia.

Vignettes

Getting Started with bcmaps
Working with bcmaps layers and point data

You can also view vignettes by typing browseVignettes("bcmaps") in your R session after you install bcmaps.

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 the B.C. Data Catalalogue (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.

bcmaps's People

Contributors

ateucher avatar bevingtona avatar boshek avatar markjohnsonubc avatar monkmanmh avatar repo-mountie[bot] avatar stephhazlitt avatar tylerlittlefield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bcmaps's Issues

GEOS version number woes

I'm trying to run sf and rgeos revdep checks with forthcoming GEOS 3.9.0, which presents itself as "3.9.0dev". This fails in old_sf_geos():

  1. Error: works with self-intersections: sf (@test-fix_geo_problems.R#94)
  2. Error: works with other problems: sf (@test-fix_geo_problems.R#106)

These fork on GEOS < 3.8.0 for good reason, but do not try to strip trailing string extensions to the declared version number. This only matters if you care about protecting yourselves from the radical changes coming in GEOS 3.9.0. Your code presupposes that the version number is normalised, which it will be when 3.9.0 is released, but then it will be too late to modify code ahead of time. The rgeos tests earlier in the same file all pass, so I think the irritant is just expecting the sf GEOS version string to be normalised.

Add project lifecycle badge

No Project Lifecycle Badge found in your readme!

Hello! I scanned your readme and could not find a project lifecycle badge. A project lifecycle badge will provide contributors to your project as well as other stakeholders (platform services, executive) insight into the lifecycle of your repository.

What is a Project Lifecycle Badge?

It is a simple image that neatly describes your project's stage in its lifecycle. More information can be found in the project lifecycle badges documentation.

What do I need to do?

I suggest you make a PR into your README.md and add a project lifecycle badge near the top where it is easy for your users to pick it up :). Once it is merged feel free to close this issue. I will not open up a new one :)

Outside of BC layer

To flesh out some plotting capabilities of bcmaps I wonder if it might be useful to have an "external to bc" layer. For example, we typically may plot the province using either bc_bound() or bc_bound_hres() like this:
image

If we had an outside_bc_border() layer like this:
image

We could combine them in instances where don't want BC floating on its own in space:
image

Is this something we'd want in bcmaps? Or is it better to leave up to a user to create?

Here is how I created the layer. I am still struggling with how to create a perfectly square box on a projected surface. Also I am currently sourcing the data from the raster package but this may not be a tenable long term solution to store over in bcmaps.rdata:

library(here)
library(raster)
library(bcmaps)
library(sf)
library(dplyr)
library(ggplot2) #dev



# Load spatial layers -----------------------------------------------------

data_path <- here("data")

canada_border <- raster::getData('GADM', country="CAN", path = data_path, level=1) 

usa_border <- raster::getData('GADM', country="USA", path = data_path, level=1) 

## Square box on projected surface
coords = list(matrix(c(-142, 61,
                       -138, 47,
                       -114, 47,
                       -110, 61,
                       -142, 61),
                ncol = 2,
                byrow = TRUE))

outside_bc_box <- st_polygon(coords) %>%
  st_sfc(crs = 4326) %>%
  transform_bc_albers() 


# Spatial manipulations ---------------------------------------------------

canada_border <- st_as_sf(canada_border) %>%
  transform_bc_albers()

usa_border <- st_as_sf(usa_border) %>%
  transform_bc_albers()


outside_bc_border <- rbind(canada_border, usa_border) %>%
  st_intersection(outside_bc_box) %>%
  filter(!NAME_1 == "British Columbia")


# Plots -------------------------------------------------------------------

ggplot() +
  geom_sf(data = bc_bound_hres(), fill = "purple") +
  theme_void()

ggplot() +
  geom_sf(data = outside_bc_border) +
  theme_void()

ggplot() +
  geom_sf(data = bc_bound_hres(), fill = "purple") +
  geom_sf(data = outside_bc_border) +
  theme_void()

get_layer() should only accept character input

If bcmaps.rdata is loaded (which isn't necessary, but inevitable), and you try something like:

get_layer(bc_bound)

it can look for the object bc_bound and all sorts of strange things can happen

Add crs argument to the three cded functions

add an argument to be able to specify the projection and have the output reprojected. By default it should be bcalbers and cded is not. Otherwise the output of the cded functions do not play nicely with the other bcmaps spatial objects.

ws <- bcdc_query_geodata("51f20b1a-ab75-42de-809d-bf415a0f9c62", crs = bcalb) %>%
  filter( WATERSHED_GROUP_CODE == "PARS") %>%
  collect() %>% st_as_sf()
dem.ws <- cded_raster(aoi = ws)
crs(dem.ws)
st_crs(ws)

Add basemaps

A helpful addition to the package would be to have the basemaps from BCGW accessible through the package either at the different scales, or with an autoscale function if feasible.

Release bcmaps 1.0.1

Prepare for release:

  • devtools::build_readme()
  • Check current CRAN check results
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • urlchecker::url_check()
  • Update cran-comments.md
  • Polish NEWS

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

sf 0.6.0 causes NOTE in check for bcmaps

As per email from Edzer:

sf, under consideration at CRAN, will
generate a NOTE in bcmaps checks:

  • checking dependencies in R code ... NOTE
    Missing or unexported object: ‘sf::st_make_valid’
    consequently any code that will try to use sf::st_make_valid will break
    for the new sf, because this function has been moved to
    lwgeom::st_make_valid (as all other functions that use liblwgeom).
    package lwgeom is on CRAN, with binary OSX and Windows versions.

Add missing topics

TL;DR

Topics greatly improve the discoverability of repos; please add the short code from the table below to the topics of your repo so that ministries can use GitHub's search to find out what repos belong to them and other visitors can find useful content (and reuse it!).

Why Topic

In short order we'll add our 800th repo. This large number clearly demonstrates the success of using GitHub and our Open Source initiative. This huge success means its critical that we work to make our content as discoverable as possible; Through discoverability, we promote code reuse across a large decentralized organization like the Government of British Columbia as well as allow ministries to find the repos they own.

What to do

Below is a table of abbreviation a.k.a short codes for each ministry; they're the ones used in all @gov.bc.ca email addresses. Please add the short codes of the ministry or organization that "owns" this repo as a topic.

add a topic

That's in, you're done!!!

How to use

Once topics are added, you can use them in GitHub's search. For example, enter something like org:bcgov topic:citz to find all the repos that belong to Citizens' Services. You can refine this search by adding key words specific to a subject you're interested in. To learn more about searching through repos check out GitHub's doc on searching.

Pro Tip 🤓

  • If your org is not in the list below, or the table contains errors, please create an issue here.

  • While you're doing this, add additional topics that would help someone searching for "something". These can be the language used javascript or R; something like opendata or data for data only repos; or any other key words that are useful.

  • Add a meaningful description to your repo. This is hugely valuable to people looking through our repositories.

  • If your application is live, add the production URL.

Ministry Short Codes

Short Code Organization Name
AEST Advanced Education, Skills & Training
AGRI Agriculture
ALC Agriculture Land Commission
AG Attorney General
MCF Children & Family Development
CITZ Citizens' Services
DBC Destination BC
EMBC Emergency Management BC
EAO Environmental Assessment Office
EDUC Education
EMPR Energy, Mines & Petroleum Resources
ENV Environment & Climate Change Strategy
FIN Finance
FLNR Forests, Lands, Natural Resource Operations & Rural Development
HLTH Health
FLNR Indigenous Relations & Reconciliation
JEDC Jobs, Economic Development & Competitiveness
LBR Labour Policy & Legislation
LDB BC Liquor Distribution Branch
MMHA Mental Health & Addictions
MAH Municipal Affairs & Housing
BCPC Pension Corporation
PSA Public Safety & Solicitor General & Emergency B.C.
SDPR Social Development & Poverty Reduction
TCA Tourism, Arts & Culture
TRAN Transportation & Infrastructure

NOTE See an error or omission? Please create an issue here to get it remedied.

Use bcdata as backend for relevant layers

Is it worth thinking about the future use cases of bcmaps versus bcdata? For map layers available with bcdata should users use that package to ensure always grabbing the most up-to-date versions (without any tinkering with bcmapsdata)? Perhaps bcmaps becomes the home for open layers from the 🇨🇦 open data catalogue, maps not available via WMS/WFS, and a set of helper functions (e.g. bc_neighbours())? Thoughts @ateucher @boshek?

Issues with transform_bc_albers on certain files

Hello,

I'm trying to reproject a sf object (IAF_tnsct_sf - originally in epsg 4326) into Albers but the geometry seems off by 1000 and the x coords are positive when I do so. Any suggestions on how to fix this?

Thanks,
Joanna


OGR data source with driver: ESRI Shapefile
Source: "/Users/joburgar/Google Drive/20190629_iaf_jburgar/gis_1701scbat_iaf/03_t3_bioacoustics", layer: "abm_iaf_transect"
with 8 features
It has 16 fields
Integer64 fields read as strings: OID_ SymbolID
Warning message:
In readOGR(dsn = "./03_t3_bioacoustics", layer = "abm_iaf_transect") :
Z-dimension discarded

class(IAF_tnsct) # sp class
[1] "SpatialLinesDataFrame"
attr(,"package")
[1] "sp"

convert to sf object

IAF_tnsct_sf <- st_as_sf(IAF_tnsct)
class(IAF_tnsct_sf) # sf class
[1] "sf" "data.frame"

st_crs(IAF_tnsct_sf) # EPSG: 4326
Coordinate Reference System:
EPSG: 4326
proj4string: "+proj=longlat +datum=WGS84 +no_defs"
extent(IAF_tnsct_sf)
class : Extent
xmin : -123.0646
xmax : -121.3979
ymin : 49.00224
ymax : 49.34879

IAF_tnsct_sf_alb <- transform_bc_albers(IAF_tnsct_sf)
st_crs(IAF_tnsct_sf_alb) # EPSG: 3005
Coordinate Reference System:
EPSG: 3005
proj4string: "+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
extent(IAF_tnsct_sf_alb)
class : Extent
xmin : 1214444
xmax : 1336605
ymin : 448779
ymax : 487261.3

Archive.zip

Add `coord_bc()` function to specify ggplot2 bounding box in lat/long

Hi,
This is a great package and I'm starting to use it more often.
I'm posting here to get input on mapping sub-regions of BC using ggplot with the bc_bound_hres().
Currently for quickly mapping I convert the lat/lon of my study area to UTM and enter in coord_sf(), e.g.:
ggplot() + geom_sf(bc_bound_hres(), fill = "grey", colour = "black") + coord_sf(xlim = c(600000, 800000), ylim = c(745000, 1000000))
If it is possible to set limits in lat/lon it would be faster and more intuitive, but I haven't figured out how best to do that yet. Pardon if there is an obvious way of doing this.
Cheers!

Add project lifecycle badge

No Project Lifecycle Badge found in your readme!

Hello! I scanned your readme and could not find a project lifecycle badge. A project lifecycle badge will provide contributors to your project as well as other stakeholders (platform services, executive) insight into the lifecycle of your repository.

What is a Project Lifecycle Badge?

It is a simple image that neatly describes your project's stage in its lifecycle. More information can be found in the project lifecycle badges documentation.

What do I need to do?

I suggest you make a PR into your README.md and add a project lifecycle badge near the top where it is easy for your users to pick it up :). Once it is merged feel free to close this issue. I will not open up a new one :)

Flag layer size when given the option to download

This is a great addition and will really speed up the process when building maps 100 times when trouble shooting. I think it may be worthwhile to put 'layer file size' when given the option to download a layer. I have no idea how large they are but if they are 100 megs it may start impacting local HD space (for those of us with small SSD). Great work!

Remove bcdc_sf class before caching

Some data are directly drawn from the BC data catalogue using bcdata and therefore still have the bcdc_sf class:

library(bcmaps)
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1

class(bc_cities())
#> bc_cities was updated on 2020-08-26
#> [1] "bcdc_sf"    "sf"         "tbl_df"     "tbl"        "data.frame"

We should strip that first class.

New workflow for layers from Canada data

layers: bc_bound_hres, 2x watercourses

options:

  • function(s) to download, process, and cache from Canada
  • bundle in package (probably not feasible due to size)
  • host as assets in a GH release similar to BEC and TSA

Rename watersheds layer

This layer should be renamed to better distinguish it from wsc_boundaries(). Actual prefix is pending additional research.

Add project lifecycle badge

No Project Lifecycle Badge found in your readme!

Hello! I scanned your readme and could not find a project lifecycle badge. A project lifecycle badge will provide contributors to your project as well as other stakeholders (platform services, executive) insight into the lifecycle of your repository.

What is a Project Lifecycle Badge?

It is a simple image that neatly describes your project's stage in its lifecycle. More information can be found in the project lifecycle badges documentation.

What do I need to do?

I suggest you make a PR into your README.md and add a project lifecycle badge near the top where it is easy for your users to pick it up :). Once it is merged feel free to close this issue. I will not open up a new one :)

Error in download_file_from_release

Hello Andy @ateucher, Stephanie @stephhazlitt and Sam @boshek ,
I encountered an issue when I was using bec() and tsa() functions. The error message was:

library(bcmaps)
library(bcmapsdata)
a <- bec()
Error in download_file_from_release(fname, fpath, release = release, force = force) : 
  No assets matching filename tsa.rds in latest release.

The session inform was:

`
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

other attached packages:
[1] bcmapsdata_0.3.2 bcmaps_0.18.0 sf_0.8-0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 class_7.3-15 rappdirs_0.3.1
[4] grid_3.6.0 R6_2.4.1 jsonlite_1.6
[7] DBI_1.1.0 magrittr_1.5 e1071_1.7-3
[10] units_0.6-5 KernSmooth_2.23-15 httr_1.4.1
[13] curl_4.3 tools_3.6.0 compiler_3.6.0
[16] classInt_0.4-2
`
Any idea where the problem is? Please let me know if you need more information for debuging. Thank you very much.

Yong

GH authentication changes?

your personal access token using libcurl/7.64.1 r-curl/4.3 httr/1.4.1 was used as part of a query parameter to access an endpoint through the GitHub API:

https://api.github.com/repositories/107592256/releases

Please use the Authorization HTTP header instead, as using the access_token query parameter is deprecated.

Depending on your API usage, we'll be sending you this email reminder once every 3 days for each token and User-Agent used in API calls made on your behalf.
Just one URL that was accessed with a token and User-Agent combination will be listed in the email reminder, not all.

Visit https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters for more information.

Release bcmaps 1.0

Prepare for release:

  • devtools::build_readme()
  • Check current CRAN check results
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • urlchecker::url_check()
  • Update cran-comments.md
  • Polish NEWS

Submit to CRAN:

  • usethis::use_version('major')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Tweet

Old version of NRD

Just noticed that the Natural Resource Districts layer (called with the bcmaps function bcmaps::nr_districts()) is an old version of the districts. The data catalogue has a newer version (found here: https://catalogue.data.gov.bc.ca/dataset/natural-resource-nr-district).

The only difference is that the Vanderhoof and Fort St. James districs have been merged into a single district named Stuart Nechako.

Great package as always - my go to for quick access to pretty maps!

image

Support for Health Boundaries?

Hello,
was very excited to see this repo. I read through the list, but didn't find support for boundaries for health service system units (please see http://www2.gov.bc.ca/gov/content/data/geographic-data-services/land-use/administrative-boundaries/health-boundaries).
I am a postdoctoral researcher, starting to look at surveillance and monitoring at provincial level and searching for the maps the correspond to these boundaries. I am specifically looking for something that can work in R and ggplot universe.

Create `bc_neighbours` from bcdata

library(bcdata)
library(sf)

coords = list(matrix(c(-142, 59.9,
                       -137.69, 47,
                       -114.31, 47,
                       -110, 59.9,
                       -142, 59.9),
                     ncol = 2,
                     byrow = TRUE))

outside_bc_box <- st_polygon(coords) %>%
  st_sfc(crs = 4326) %>%
  st_transform(3005) %>% 
  st_bbox()


bc_neighbours <- bcdc_query_geodata('b9bd93e1-0226-4351-b943-05c6f80bd5da') %>% 
  filter(BBOX(c(109930.2, 294451.3, 1890069.8, 1758438.9))) %>% 
  collect()

plot(bc_neighbours)

Cache location incorrect on Linux

From CRAN:

Checking this on Linux creates and leaves behind

~/.local/share/bcmaps

in violation of the CRAN Policy's

Packages should not write in the user’s home filespace (including
clipboards), nor anywhere else on the file system apart from the R
session’s temporary directory (or during installation in the location
pointed to by TMPDIR: and such usage should be cleaned up). Installing
into the system’s R installation (e.g., scripts to its bin directory)
is not allowed.

Limited exceptions may be allowed in interactive sessions if the
package obtains confirmation from the user.

For R version 4.0 or later (hence a version dependency is required or
only conditional use is possible), packages may store user-specific
data, configuration and cache files in their respective user
directories obtained from tools::R_user_dir(), provided that by
default sizes are kept as small as possible and the contents are
actively managed (including removing outdated material).

Can you please change as necessary, ideally using the
tools::R_user_dir() mechanism where available?

Please fix before 2021-01-26 to safely retain your package on CRAN.

We are using rappdirs::user_data_dir(), which on Unix uses ~/.local/share/<appname>.

Perhaps we should use tools::R_user_dir() (R >= 4.0) or rappdirs::user_cache_dir() which uses ~/.local/cache/<appname>?

From the help for tools::R_user_dir(), it creates an R subfolder in the user/cache directory (~/.local/cache/R/<appname> - hopefully rappdirs can do the same for R < 4.0.

Checking package with R_FUTURE_PLAN=multisession reveals problems

UPDATE 2020-09-21: I've posted R CMD check output for another package. Please discard this issue.

Hi, I run revdep checks where I force packages to use 'multisession' futures instead of 'sequential' by default. This will help assert that the package work in parallel processing. When I did this for your package, the following error popped up:

$ export R_FUTURE_PLAN=multisession
$ R CMD check https://cran.r-project.org/src/contrib/bcmaps_0.18.1.tar.gz
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.