Skip to content

Instantly share code, notes, and snippets.

library(tidyhydat)
library(dplyr)
library(purrr)
rl_stations <- realtime_stations(prov_terr_state_loc = "BC")
hy_stations <- hy_stations(prov_terr_state_loc = "BC")
## all stations that are both in hydat and have a realtime record
bc_stations <- rl_stations %>%
inner_join(hy_stations, by = "STATION_NUMBER")
library(tidyverse)
library(bcmaps)
library(tmap)
library(sf)
library(rayshader)
library(raster)
ws <- wsc_drainages() %>%
filter(SUB_SUB_DRAINAGE_AREA_NAME %in% c("Quesnel", "Clearwater (B.C.)", "Lower Fraser - Williams Lake"))
library(sf)
library(dplyr)
library(bcdata)
get_bc_fsa <- function() {
x <- 'http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfsa000b16a_e.zip'
temp_zip <- file.path(tempdir(), basename(x))
export_dir <- tempdir()
library(rnaturalearth)
library(ggplot2)
library(sf)
country_poly <- ne_countries(scale = 50, returnclass = "sf")
res <- st_read("http://ihp-wins.unesco.org/geoserver/wfs?srsName=EPSG%3A4326&outputFormat=json&service=WFS&srs=EPSG%3A4326&request=GetFeature&typename=geonode%3Aworld_rivers&version=1.0.0&access_token=3165106ba28e11e997a3005056062634") %>%
# Copyright 2019 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.
@boshek
boshek / notes.md
Last active January 10, 2019 23:09
Diagnosing bcmaps.rdata problem
> devtools::install_github("bcgov/bcmaps.rdata")
Downloading GitHub repo bcgov/bcmaps.rdata@master
   checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' ...
   checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' ...  
√  checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' (390ms)
-  preparing 'bcmaps.rdata': (11.9s) 
   checking DESCRIPTION meta-information ... 
   checking DESCRIPTION meta-information ...  
@boshek
boshek / spinning_hydrograph.R
Created October 16, 2018 03:22
Animate a hydrograph in a circle
## based on this code: https://twitter.com/JustTheSpring/status/1049468485334523906
library(tidyverse)
library(lubridate)
library(gganimate)
library(tidyhydat)
stn <- "08MF005"
flow_data <- hy_daily_flows(stn, start_date = "2012-01-01", end_date = "2016-12-31") %>%
filter(!is.na(Value)) %>%
@boshek
boshek / rasterizing
Last active September 26, 2018 19:04
Comapring POSTGIS rasterization with fasterize
library(sf)
library(dplyr)
library(fasterize)
shape <- "MULTIPOLYGON (((1126095 1246073, 1126221 1246053, 1126358 1246059, 1126383 1245909, 1126457 1245800, 1126605 1245831, 1126756 1245812, 1126812 1245652, 1126805 1245526, 1126841 1245377, 1126859 1245227, 1126868 1245077, 1126881 1244927, 1126949 1244805, 1126954 1244667, 1126806 1244635, 1126658 1244602, 1126508 1244591, 1126358 1244591, 1126283 1244701, 1126248 1244825, 1126256 1244951, 1126219 1245100, 1126197 1245249, 1126175 1245374, 1126145 1245498, 1126114 1245622, 1126025 1245743, 1125919 1245839, 1125803 1245897, 1125638 1245928, 1125547 1246037, 1125693 1246143, 1125842 1246150, 1126095 1246073)))"
tictoc::tic()
## Actually connect to the database
@boshek
boshek / calculating_area_sf.md
Created September 19, 2018 21:23
Calculate Area with sf

Calculate Area with sf

library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
library(gganimate)
library(ggplot2)
library(tidyhydat)
library(tidyverse)

Just do it with one station