Skip to content

Instantly share code, notes, and snippets.

@lbusett
lbusett / fix_kml.R
Last active Jul 15, 2020
Fix a kml exported from GEE so that holes are respected
View fix_kml.R
fix_kml <- function(infile, outfile) {
intext <- readLines(con <- file(infile))
out <- list()
ll = 1
indout <- 1
# cycle on lines of input
while(ll <= length(intext)){
curline <- intext[ll]
# If a "hole block" is starting, check if there is only
View get_utm_crs
# funzioni necessarie
find_UTM_zone <- function(longitude, latitude) {
# Special zones for Svalbard and Norway
if (latitude >= 72.0 && latitude < 84.0 )
if (longitude >= 0.0 && longitude < 9.0)
return(31);
if (longitude >= 9.0 && longitude < 21.0)
return(33)
View scrip_convert_kml
#install.packages("gdalUtilities")
library(gdalUtilities)
in_folder <- "/home/lb/nr_data/fire_cci/reference/Africa/Landsat8/Luini/178066/kml_lorenzo/"
out_folder <- file.path(in_folder, "shape_conversion")
dir.create(out_folder)
kml_files <- list.files(in_folder, pattern = "kml$", full.names = TRUE)
for(ff in kml_files) {
print(ff)
out_file <- file.path(out_folder,
View gist:fbffb683e79e338c21f346843a983811
ref_dir <- system.file("extdata/example_files/out_ref", package = "sen2r")
testthat::test_that(
"Tests on custom mask on TOA with smoothing and buffering, with save binary mask", {
outdir_6 <- file.path(tempdir(), "out_test6")
dir.create(dirname(outdir_6), showWarnings = FALSE)
exp_outpath_6 <- file.path(outdir_6, "TOA", "S2A1C_20170703_022_Barbellino_TOA_10.tif")
exp_outpath_msk <- file.path(outdir_6, "MSK", "S2A1C_20170703_022_Barbellino_MSK_10.tif")
unlink(exp_outpath_6)
@lbusett
lbusett / bibtex_2academic.R
Created Mar 13, 2018
script for importing publications from a "bibtex" file to a hugo-academic website
View bibtex_2academic.R
#' @title bibtex_2academic
#' @description import publications from a bibtex file to a hugo-academic website
#' @author Lorenzo Busetto, phD (2017) <lbusett@gmail.com>
bibtex_2academic <- function(bibfile,
outfold,
abstract = FALSE,
overwrite = FALSE) {
require(RefManageR)
@lbusett
lbusett / points_in_distance_parallel.R
Last active Sep 23, 2020
function for finding all points within X meters of a point
View points_in_distance_parallel.R
points_in_distance_parallel <- function(in_pts,
maxdist,
ncuts = 10) {
require(doParallel)
require(foreach)
require(data.table)
require(sf)
# convert points to data.table and create a unique identifier
pts <- data.table(in_pts)
@lbusett
lbusett / lint_exclude
Created Nov 28, 2017
exclude one lintr
View lint_exclude
lint_package(".",
linters = with_defaults(
object_camel_case_linter = NULL,
object_snake_case_linter
)
)
View gist:9c45879078c3a03cbb5d18b5427cd60b
From:
https://stackoverflow.com/questions/34416892/how-to-add-a-scale-bar-in-ggplot-map
library(maps)
library(maptools)
library(ggplot2)
library(grid)
#
@lbusett
lbusett / lb_tricks.R
Last active Aug 3, 2017
Various "R" tricks
View lb_tricks.R
# String manipulation
### Print an integer number with trailing zeroes
number = 1
sprintf("%03i", number)
### use "easier" patterns with wildcards for regexp
glob2rx('*.tif')
You can’t perform that action at this time.