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 / clip_raster_with_sf.R
Last active July 20, 2022 15:17
Clip a raster with sf polygon boundaries in R
if("fasterize" %in% rownames(installed.packages()) == FALSE) {install.packages("fasterize")}
if("raster" %in% rownames(installed.packages()) == FALSE) {install.packages("raster")}
clip_raster_with_sf <- function(rast, sf){
r_mask <- fasterize::fasterize(sf, rast)
r_masked <- raster::mask(rast, r_mask)
## Create catchment areas based on travel time ##
# Code by Giacomo Falchetta #
# 11/02/2021 #
##############
library(sf)
library(raster)
library(gdistance)
library(tidyverse)
library(data.table)
@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)