Skip to content

Instantly share code, notes, and snippets.

View tim-salabim's full-sized avatar
💭
not much

tim-salabim

💭
not much
View GitHub Profile
@tim-salabim
tim-salabim / mapview_watcher.R
Created March 10, 2020 18:30
Use {later} to watch for sf objects and automatically mapview them
# This will watch your global environment for sf objects and mapview them automagically.
library(later)
library(mapview)
last_value = NULL
dir <- tempfile()
dir.create(dir)
htmlFile <- file.path(dir, "index.html")
@tim-salabim
tim-salabim / mesh3d_and_leafgl.R
Last active March 10, 2020 09:14
use leafgl to visualise mesh3d
library(ggplot2)
library(leafgl)
library(leaflet)
library(sf)
sfx <- sf::st_transform(sf::st_cast(dplyr::filter(silicate::inlandwaters, Province == "Tasmania"), "POLYGON")[2, ], 4326)
topo <- ceramic::cc_elevation(sfx, zoom = 9)
mesh <- anglr::as.mesh3d(anglr::copy_down(anglr::DEL(sfx, max_area = .0001),
library(V8)
library(mapview)
library(geojsonsf)
ct = v8(global="window")
ct$source("https://cdn.jsdelivr.net/npm/[email protected]/dist/flatgeobuf-geojson.min.js")
ct$get("Object.keys(window)")
fran = sf_geojson(franconia[1, ])
library(raster)
library(sf)
library(sp)
library(elevatr)
library(mapview)
library(magick)
library(smoothr)
library(RColorBrewer)
# download from http://www.geodaten.bayern.de/opendata/Verwaltungsgebiete_shp_epsg31468.zip
@tim-salabim
tim-salabim / ghmd2pdf.R
Created April 24, 2019 12:47
convert github_document .md files to pdf
ghmd2pdf = function(input, output = NULL, pandoc_opts = NULL) {
# input = "01_analysis/0110_code/01101_r_scripts/030_yield_by_oven.md"
if (is.null(output)) {
output = paste0(tools::file_path_sans_ext(input), ".pdf")
}
lns = readLines(input)
idx = grep("<img src=", lns)
@tim-salabim
tim-salabim / viewNodes.R
Created January 15, 2019 09:46
view polygon/line nodes
viewNodes = function(x, cex = 6) {
crds = sf::st_coordinates(x)[, c("X", "Y")]
n = nrow(crds)
pts = sf::st_as_sf(
data.frame(
id = 1:n,
x = crds[, "X"],
y = crds[, "Y"]
),
coords = c("x", "y"),
@tim-salabim
tim-salabim / buildings_ch.R
Created October 15, 2018 16:57
Visualising 1.8 mio buldings in switzerland using leaflet.glify
library(sf)
library(leaflet)
library(leaflet.glify)
library(mapview)
bu = read_sf("/media/timpanse/d8346522-ef28-4d63-9bf3-19fec6e13aab/bu_lenovo/software/testing/mapview/switzerland/buildings.shp")
st = seq(1, nrow(bu), 5e5)
nd = st + 5e5 - 1
nd[length(nd)] = nrow(bu)
@tim-salabim
tim-salabim / on_render.md
Last active February 17, 2019 19:47
various snippets for modifying map state after creation

adjust zoom level

helpful when using mapshot/saveWidget + webshot to ensure map is zoomed to desired level

### zoom to after rendering (relevant for mapshot)
library(mapview)

map = mapview(franconia)@map
https://jsfiddle.net/7yf6upg5/4/
@tim-salabim
tim-salabim / cols.json
Created September 20, 2018 15:32
cols.json
This file has been truncated, but you can view the full file.
var cols =
[{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.3294},{"r":0.2667,"g":0.0039,"b":0.32