Skip to content

Instantly share code, notes, and snippets.

@ratnanil
ratnanil / json-to-sf
Last active May 30, 2024 06:57
Import Google Timeline / Location History
# 1. go to https://takeout.google.com/
# 2. Deselect all "Products"
# 3. Select only the following product: Location History (Timeline)
# 4. Follow the other steps to get a json export of your Location history
# 5. Download and extract the data in your RStudio Project folder
# 6. Follow the script below
library(sf)
@ratnanil
ratnanil / get_data.R
Last active April 4, 2024 23:05
Create Fishnet from swissAlti3D URLs
library(readr)
library(tidyr)
library(sf)
library(dplyr)
library(purrr)
library(glue)
ullr2poly <- function(xmin, ymin, xmax, ymax){
c(1,2,1,4,3,4,3,2,1,2) |>
sapply(\(x)c(xmin, ymin, xmax, ymax)[x]) |>
matrix(ncol = 2, byrow = TRUE) |>
# from here:
# https://github.com/rstudio/gt/blob/ff878e10d21a3ba897c5f99801b796da8fb637fa/R/helpers.R#L2496-L2536
adjust_luminance <- function(colors, steps) {
stopifnot(steps < 2, steps > -2)
rgb_matrix <- t(grDevices::col2rgb(colors, alpha = TRUE)) / 255
alpha <- rgb_matrix[, "alpha"]
luv_matrix <-
grDevices::convertColor(rgb_matrix[, 1:3], "sRGB", "Luv")
h <- atan2(luv_matrix[, "v"], luv_matrix[, "u"]) * 180 / pi
c <- sqrt(luv_matrix[, "u"]^2 + luv_matrix[, "v"]^2)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.