Skip to content

Instantly share code, notes, and snippets.

View jlehtoma's full-sized avatar

Joona Lehtomäki jlehtoma

View GitHub Profile
@jlehtoma
jlehtoma / convert.sh
Last active August 29, 2015 14:00
Pandoc table conversion
#!/bin/bash
pandoc in.md -o out.pdf
pandoc in.md -o out.tex
pandoc out.tex -o out2.pdf
@jlehtoma
jlehtoma / batchreplace.sh
Created March 24, 2014 08:17
Batch replace ASCII rasters with GeoTIFF rasters
#!/bin/bash
for FILE in *.asc
do
BASENAME=$(basename $FILE .asc)
OUTFILE=${BASENAME}.tif
echo "Processing: ${BASENAME}.asc"
gdal_translate -of GTiff -co COMPRESS=DEFLATE $FILE $OUTFILE
library(maptools)
library(rgdal)
library(rgeos)
setwd("~/type1")
species <- 'speciesX1'
list_shp <- list.files(path=species, pattern="*.shp", full.names = TRUE,
recursive = TRUE, include.dirs = FALSE)
shp_objects <- lapply(list_shp, function(x) {readOGR(dsn=x,
layer=ogrListLayers(x))})
@jlehtoma
jlehtoma / buffer_compare.R
Created September 10, 2013 07:16
Example of how 2 sets of coordinates (in the same projection) can be compared for proximity.
# Buffer the coordinates with a desired distance
sp.espoo.etrs89.buffer <- gBuffer(sp.espoo.etrs89, byid=TRUE, width=100)
sp.espoo.etrs89.buffer <- SpatialPolygonsDataFrame(sp.espoo.etrs89.buffer,
sp.espoo.etrs89@data)
sp.tarto.etrs89.buffer <- gBuffer(sp.tarto.etrs89, byid=TRUE, width=100)
sp.tarto.etrs89.buffer <- SpatialPolygonsDataFrame(sp.tarto.etrs89.buffer,
sp.tarto.etrs89@data)
# See which SpatialPoints from the KML files fall within the buffer from sp
@jlehtoma
jlehtoma / map.geojson
Created August 13, 2013 15:39
via:geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jlehtoma
jlehtoma / fcompare.py
Last active December 19, 2015 13:49
Compare files in 2 folders and determine exact or similar filename matches.
#!/usr/bin/env python
""" Utility script to compare whether the content of 2 folders appear to be
same.
Similarity is based on simple file name matching.
"""
import argparse
from difflib import get_close_matches
library(reshape)
library(ggplot2)
dat <- data.frame(Paikka=rep(c("Hanko", "Helsinki","Turku"), 4),
Vuosi=factor(rep(c(2009, 2010, 2011, 2012), each=3)),
Prosentti=runif(12, 0, 1))
# Barplot
ggplot(dat, aes(Paikka, Prosentti, fill=Vuosi)) +
geom_bar(position="dodge", stat="identity")
@jlehtoma
jlehtoma / eureffin_to_wgs84_example.py
Last active December 17, 2015 17:29
Example for EUREF-FIN coordinates transformation into WGS84 CRS using GDAL
#!/usr/bin/env python
# Requires GDAL with python installed https://pypi.python.org/pypi/GDAL
import osgeo.ogr as ogr
import osgeo.osr as osr
# Adapted from http://lists.osgeo.org/pipermail/gdal-dev/2009-October/022284.html
# Create wkt string of point coords
library(data.table)
read.weather.data.table <- function(folder, hilas, jdate.start, jdate.end, years='All') {
# List all the csv files in the folder
csv.files <- list.files(folder, "\\.csv$", full.names = TRUE)
# Create an empty list to hold the content of each csv file
csv.files.data <- list()
read.weather.data <- function(folder, hilas, jdate.start, jdate.end, years='All') {
# List all the csv files in the folder
csv.files <- list.files(folder, "\\.csv$", full.names = TRUE)
# Create an empty list to hold the content of each csv file
csv.files.data <- list()
col.names = c("hila", "year", "x1", "x2", "temp", "rain", "jdate")