Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
locations <- data.frame(id = "E309447")

library(rems)
library(dplyr)

hist_db <- attach_historic_data()
filtered_historic <- hist_db %>% 
  filter(EMS_ID %in% locations$id) %>% 
  collect()
@ateucher
ateucher / install-saga-mac
Last active November 1, 2019 05:37
Install SAGA GIS on a Mac (2019-10-30)
# If you haven't installed homebrew, see some instructions here:
# https://github.com/bcgov/envreportutils/wiki/Macbook-Pro-Setup-for-Data-Science-at-EnvReportBC#homebrew
# These have not been tested on macOS Catalina, but the Mojave instructions _should_ work.
# If you run into issues, this looks like it might be helpful:
# https://medium.com/faun/macos-catalina-xcode-homebrew-gems-developer-headaches-cf7b1edf10b7
# The osgeo homebrew tap is in a bit of a mess, so `brew install saga-gis` doesn't work (as of 2019-10-30).
# This is because SAGA dependencies have been updated, but they haven't updated the brew formula for SAGA itself.
# Same goes for QGIS; and now that there is a fully self-contained signed installer, I recommend that over heomebrew for QGIS
# (https://qgis.org/en/site/forusers/download.html)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ateucher
ateucher / Dockerfile
Created July 30, 2019 18:33
Attempt at Dockerfile with filegdb write support
##
# osgeo/gdal:ubuntu-full
# This file is available at the option of the licensee under:
# Public domain
# or licensed under X/MIT (LICENSE.TXT) Copyright 2019 Even Rouault <even.rouault@spatialys.com>
# ACT: Copied from https://raw.githubusercontent.com/OSGeo/gdal/master/gdal/docker/ubuntu-full/Dockerfile
ARG PROJ_INSTALL_PREFIX=/usr/local
values <- runif(100)

# get runs where values > 0.75 (these are TRUE/FALSE)
runs <- rle(values > 0.75)

# Mask out the runs with lengths < 3
runs$values[runs$lengths < 3] <- FALSE

# Get a vector of positions that meet the run criteria
values <- runif(100)
# get runs where values > 0.75 (these are TRUE/FALSE)
runs <- rle(values > 0.75)
# Mask out the runs with lengths < 3
runs$values[runs$lengths < 3] <- FALSE
# Get a vector of positions that meet the run criteria
masked <- inverse.rle(runs)
# remotes::install_github("bcgov/bcdata", ref = "promise")
library(bcdata)
library(ggplot2)

Use bcdc_get_data() to get an entire dataset. I wouldn't recommend this for really large datasets like the FWA:

library(rgdal)
#> Loading required package: sp
#> rgdal: version: 1.4-3, (SVN revision 828)
#>  Geospatial Data Abstraction Library extensions to R successfully loaded
#>  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
#>  Path to GDAL shared files: /Users/ateucher/Rlibrary/rgdal/gdal
#>  GDAL binary built with GEOS: FALSE 
#>  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
#>  Path to PROJ.4 shared files: /Users/ateucher/Rlibrary/rgdal/proj
library(dplyr)
library(lubridate)
# sample table
foo <- tibble(
a = rnorm(5),
date = seq(Sys.Date(), by = "1 day", length.out = 5),
he = 1:5
)
@ateucher
ateucher / bc_wms_tiles.R
Last active March 28, 2019 22:45
BC WMSTiles
library(bcmaps)
library(leaflet)
library(sf)
st_transform(bc_bound(), 4326) %>%
leaflet() %>%
#add basemap
#addpolygons and make it show in three different layers, by risk level
addPolygons() %>%
addProviderTiles(providers$CartoDB.DarkMatter,