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
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
@tim-salabim
tim-salabim / leaflet.pixi_20mio
Created August 28, 2018 21:17
render millions of points with leaflet.pixi
# devtools::install_github("tim-salabim/leaflet.pixi")
library(mapview)
library(leaflet)
library(leaflet.pixi)
library(sf)
n = 1e6
df1 = data.frame(x = runif(n, -100, 30),
library(sf)
library(data.table)
library(mapview)
n = 1000
x = runif(n, 0, 2)
y = runif(n, 0, 1)
pts = st_as_sf(data.frame(id_pt = 1:n, x = x, y = y), coords = c("x", "y"))
library(osmdata)
library(mapview)
library(sf)
q0 <- opq(bbox = "Bern, Switzerland", timeout = 60)
q1 <- add_osm_feature(q0, key = 'building', value = "hospital")
x <- osmdata_sf(q1)
pols_ctr = st_centroid(x$osm_polygons)
buff = st_buffer(pols_ctr, dist = 0.0015)