Skip to content

Instantly share code, notes, and snippets.

View Martin-Jung's full-sized avatar
🦆
Fixing bugs and saving ducks...

Martin Jung Martin-Jung

🦆
Fixing bugs and saving ducks...
View GitHub Profile
@Martin-Jung
Martin-Jung / country_bioregion_intersection.csv
Created August 10, 2023 09:24
Country and bioregion intersection
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
countryname code biogeoregion
Albania Alpine Alpine Bio-geographical Region
Albania Mediterranean Mediterranean Bio-geographical Region
Andorra Alpine Alpine Bio-geographical Region
Andorra Mediterranean Mediterranean Bio-geographical Region
Austria Alpine Alpine Bio-geographical Region
Austria Continental Continental Bio-geographical Region
Austria Pannonian Pannonian Bio-geographical Region
Belgium Continental Continental Bio-geographical Region
Belgium Atlantic Atlantic Bio-geographical Region
################# other format ##################
#' @param x [`Raster-class`],
#' [sf::st_sf()],
#' [`SpatialPolygonsDataFrame-class`],
#' [`SpatialLinesDataFrame-class`],
#' [`SpatialPointsDataFrame-class`],
#' [data.frame()] object,
#' [numeric()] vector, or
#' [matrix()] specifying the planning units to use in the reserve
#' design exercise and their corresponding cost. It may be desirable to
@Martin-Jung
Martin-Jung / github.R
Created August 30, 2021 21:21 — forked from z3tt/github.R
Configure GitHub for Rstudio
#### 1. Sign up at GitHub.com ################################################
## If you do not have a GitHub account, sign up here:
## https://github.com/join
# ----------------------------------------------------------------------------
#### 2. Install git ##########################################################
## If you do not have git installed, please do so:
import os
import subprocess
import rasterio
def extract_bands(file, bands=None):
dataset = rasterio.open(file)
if bands is None:
bands = range(1, dataset.count + 1)
elif isinstance(bands, int):
@Martin-Jung
Martin-Jung / as.data.table.raster.R
Last active July 26, 2019 07:51
Function to convert a raster to a data.table
as.data.table.raster <- function(x, row.names = NULL, optional = FALSE,
xy = FALSE, inmem = canProcessInMemory(x, 2),
...) {
stopifnot(require("data.table"))
if(inmem) {
v <- as.data.table(raster::as.data.frame(x, row.names=row.names,
optional=optional, xy=xy, ...))
coln <- names(x)
if(xy) coln <- c("x", "y", coln)
@Martin-Jung
Martin-Jung / mapview_sync.Rmd
Created February 27, 2019 22:39 — forked from fubits1/mapview_sync.Rmd
R Mapview Sync
---
title: "R Notebook"
output: html_document
---
```{r echo=FALSE, warning=FALSE, message=FALSE}
library(tidyverse)
library(leaflet)
library(mapview)
library(sf)
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 9 columns, instead of 3. in line 8.
SS,SSB,SSBS,Sample_start_earliest,Sample_end_latest,Max_linear_extent,Landcover_sampling,Landcover_postsampling,Years_before_change
AD1_2001__Liow 1,AD1_2001__Liow 1 ,AD1_2001__Liow 1 5,1999-03-01,1999-07-03,2e3,Forest,Urban,13
AD1_2001__Liow 2,AD1_2001__Liow 2 ,AD1_2001__Liow 2 5,1999-03-01,1999-07-03,2e3,Forest,Urban,13
AD1_2006__Blanche 2,AD1_2006__Blanche 2 ,AD1_2006__Blanche 2 3,2005-01-01,2005-12-31,222.80710269545455,Forest,Agriculture,3
AD1_2006__Blanche 2,AD1_2006__Blanche 2 ,AD1_2006__Blanche 2 5,2005-01-01,2005-12-31,222.80710269545455,Shrubland,Forest,3
AD1_2006__Marshall 1,AD1_2006__Marshall 1 B,AD1_2006__Marshall 1 B 23,2003-06-04,2003-07-08,97.46794345,SparseVegetation,Grassland,4
AD1_2006__Marshall 1,AD1_2006__Marshall 1 E,AD1_2006__Marshall 1 E 26,2003-06-04,2003-07-08,154.11035005,SparseVegetation,Grassland,4
AD1_2006__Marshall 1,AD1_2006__Marshall 1 E,AD1_2006__Marshall 1 E 5,2003-06-04,2003-07-08,145.77379735,Agriculture,Grassland,4
AD1_2006__Marshall 1,AD1_2006__Marshall 1 L,AD1_2006_
#define function to calculate area between the curves
area.between.curves <- function(yAxis1, yAxis2, xAxis)
{
d <- c(yAxis2 - yAxis1)[-1]
d <- d * diff(xAxis)
neg <- sum(abs(d[which(d < 0)]))
pos <- sum(d[which(d > 0)])
<html><head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<style>
html, body { background-color: white; }
table { border-collapse:collapse; border:none; }
caption { font-weight: bold; text-align:left; }
td { }
.thead { border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; }
.tdata { padding:0.2cm; text-align:left; vertical-align:top; }
.arc { background-color:#f2f2f2; }