Skip to content

Instantly share code, notes, and snippets.

View giacfalk's full-sized avatar
🎯
Focusing

Giacomo Falchetta giacfalk

🎯
Focusing
View GitHub Profile
@giacfalk
giacfalk / VIIRS_VNP46_Black_Marble_h5_to_raster_R.R
Created October 29, 2019 10:27
Bulk convert VIIRS VNP46A1 Black Marble product from h5 to GeoTIFF using R
library(raster)
library(rhdf5)
library(rgdal)
library(maps)
# manually define the working directory containing the Black Marble VNP46A1 files
wd <- "C:\\myblackmarblefiles"
# List h5 files in the specified directory
setwd(wd)
@thbaumann
thbaumann / wfs_to_local_file.bat
Last active September 19, 2025 20:44
download wfs to shapefile or gepacke with ogr2ogr
@echo off
set OSGEO4W_ROOT=C:\OSGeo4W64
set basis_url="https://www.geodatenportal.sachsen-anhalt.de/gfds/ws/wfs/942f5d74-6c2b-263a/GDI-LSA_Schutzgebiete/ows.wfs?REQUEST=GetCapabilities&SERVICE=WFS"
set layer="sg:lau_br_lsa"
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
@scbrown86
scbrown86 / polygonizer.R
Last active February 16, 2021 15:29 — forked from Pakillo/polygonizer.R
Convert raster to polygon using GDAL
# Convert raster to polygon using GDAL
## edited 2019-03-27 to use sf::st_read
polygonise <- function(x, outshape=NULL, gdalformat = 'ESRI Shapefile',
pypath=NULL, readpoly=TRUE, quietish=TRUE) {
## x: an R Raster layer, or the file path to a raster file recognised by GDAL
## outshape: the path to the output shapefile (if NULL, a temporary file will be created)
## gdalformat: the desired OGR vector format. Currently only supports ESRI Shapefile!
## pypath: the path to gdal_polygonize.py (if NULL, an attempt will be made to determine the location
## readpoly: should the polygon shapefile be read back into R, and returned by this function? (logical)
## quietish: should (some) messages be suppressed? (logical)
@eram
eram / outlook-unified-inbox.vba
Last active September 11, 2025 17:39
Outlook Unified Inbox Macro
' This macro creates a "unified inbox" - a search across all inboxes and sent items.
' Steps to use it:
' 1. Enable developer tab to see VBA console:
' Options > Customize Ribbon >
' Enable the selection field before “Developer” and OK.
' 2. Add macro:
' From the Developer tab open Visual Basic dialog
' Open VBA Add the Sub below to General context
' 3. Enable macros:
' Options > Trust Center > Trust Center Settings > Macro Settings
@scbrown86
scbrown86 / bivarRasterPlot.R
Last active September 5, 2025 14:39
Make a bivariate plot using raster data and ggplot2
# The function that produces the colour matrix
colmat <- function(nbreaks = 3, breakstyle = "quantile",
upperleft = "#0096EB", upperright = "#820050",
bottomleft = "#BEBEBE", bottomright = "#FFE60F",
xlab = "x label", ylab = "y label", plotLeg = TRUE,
saveLeg = FALSE) {
# TODO - replace any tidyr, dplyr etc. functions with data.table #
library(tidyverse)
require(ggplot2)
require(classInt)
@scbrown86
scbrown86 / diverge0.R
Created January 28, 2018 00:47 — forked from scipionesarlo/diverge0.R
Plot a rasterVis::levelplot with a colour ramp diverging around zero
diverge0 <- function(p, ramp) {
# p: a trellis object resulting from rasterVis::levelplot
# ramp: the name of an RColorBrewer palette (as character), a character
# vector of colour names to interpolate, or a colorRampPalette.
require(RColorBrewer)
require(rasterVis)
if(length(ramp)==1 && is.character(ramp) && ramp %in%
row.names(brewer.pal.info)) {
ramp <- suppressWarnings(colorRampPalette(brewer.pal(11, ramp)))
} else if(length(ramp) > 1 && is.character(ramp) && all(ramp %in% colors())) {
@scbrown86
scbrown86 / stratified.R
Last active February 16, 2021 15:29 — forked from mrdwab/stratified.R
Stratified random sampling from a `data.frame` in R
stratified <- function(df, group, size, select = NULL,
replace = TRUE, bothSets = FALSE) {
if (is.null(select)) {
df <- df
} else {
if (is.null(names(select))) stop("'select' must be a named list")
if (!all(names(select) %in% names(df)))
stop("Please verify your 'select' argument")
temp <- sapply(names(select),
function(x) df[[x]] %in% select[[x]])
@lukas-h
lukas-h / license-badges.md
Last active October 20, 2025 22:24
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)

@pbaylis
pbaylis / 00_spatial_interpolation.R
Last active February 27, 2022 02:16
Sample R spatial interpolation code. First fills in missing obs using CDF method, then interpolates to a grid. Useful for converting weather station to gridded data. Uses IDW but that could easily be changed.
library(foreign)
library(data.table)
library(zoo)
library(Hmisc)
library(gstat)
library(sp)
rm(list=ls())
# Fill in missing data ----
sm.thresh <- 0.9 # Min proportion of obs that must be in a station-month
@christophergandrud
christophergandrud / source_lines.R
Created December 1, 2014 14:08
Source specific lines from a file in R
#' Source specific lines in an R file
#'
#' @param file character string with the path to the file to source.
#' @param lines numeric vector of lines to source in \code{file}.
source_lines <- function(file, lines){
source(textConnection(readLines(file)[lines]))
}