Blog Archives

R GIS: Terrain Analysis for Polygons as Simple as it Gets!

June 18, 2013
By
R GIS: Terrain Analysis for Polygons as Simple as it Gets!

library(rgdal)library(raster)alt gadm gadm_sub plot(alt)plot(gadm_sub, add=T)asp slo > extract(slo, gadm_sub, fun = mean, na.rm = T, small = T, df = T) ID slope1 1 9.9590532 2 1.0474433 3 7.4561654 4 1.6737865 5 11.946553> extract(asp, gadm_sub, fun = mean, na.rm = T, small...

Read more »

Use R to Bulk-Download Digital Elevation Data with 1" Resolution

June 18, 2013
By

Here's a little r-script to convenientely download high quality digital elevation data, i.e. for the Alps, from HERE:require(XML)dir.create("D:/GIS_DataBase/DEM/")setwd("D:/GIS_DataBase/DEM/")doc urls names for (i in 1:length(urls)) download.file(urls, names) # unzip all files in dir and delete them afterwardssapply(list.files(pattern = "*.zip"), unzip)unlink(list.files(pattern = "*.zip"))p.s.: Also check raster::getData which pulls SRTM data at 90m resolution for a location / region!

Read more »

R Quick Tip: Shutdown Windows after Script Has Finished

May 21, 2013
By

Quite often I have long procedures running and want to do this over night. However, my computer would still be running all night after the script has finished. This is easily circumvented by the following lines that I put at the end of such a script:# set working dir# setwd("C:/Users/Kay/Desktop")# long procedure:for(i in 1:1e+5) {cat(i); cat("\n..................\n")}d # save...

Read more »

Creating a QGIS-Style (qml-file) with an R-Script

May 6, 2013
By
Creating a QGIS-Style (qml-file) with an R-Script

How to get from a txt-file with short names and labels to a QGIS-Style (qml-file)? I used the below R-script to create a style for this legend table where I copy-pasted the parts I needed to a txt-file, like for the WRB-FULL (WRB-FULL: Full soil code o...

Read more »

Programmatically Download CORINE Land Cover Seamless Vector Data with R

April 21, 2013
By
Programmatically Download CORINE Land Cover Seamless Vector Data with R

Thanks to a helpful SO-Answer I was able to download all CLC vector data (43 zip-files) programmatically:require(XML)path_to_files dir.create(path_to_files)setwd(path_to_files)doc urls # function to get zip file namesget_zip_name # function to plug into sapplydl_urls # download all zip-filessapply(urls, dl_urls)# function for unzippingtry_unzip # unzip all files in dir and delete them afterwardssapply(list.files(pattern = "*.zip"),...

Read more »

Download File from Google Drive/Docs Programmatically with R

April 11, 2013
By

Following up my lattest posting on how to download files from the cloud with R..dl_from_GoogleD ## Arguments:## output = output file name## key = Google document key## format = output format (pdf, rtf, doc, txt..)## Note: File must be shareable! ...

Read more »

Tweaking Movie Subtitles with R

April 10, 2013
By
Tweaking Movie Subtitles with R

I use R to fix subtitles that are not in sync with my movies. For the example below the subs were showing too early - so I added some time to each sequence in the srt file. For simplicity I used exactly 1 second in the below example.You'll see that I use my function dl_from_dropbox(), on which I wrote...

Read more »

Download Files from Dropbox Programmatically with R

April 10, 2013
By

Here is a usefull snippet that I stole from qdap::url_dl to download files from my Dropbox to the working directory.Argument x is the document name and d the document key. dl_from_dropbox require(RCurl) ...

Read more »

Convert OpenStreetMap Objects to KML with R

December 22, 2012
By

A quick geo-tip:With the osmar and maptools package you can easily pull an OpenStreetMap object and convert it to KML, like below (thanks to adibender helping out on SO). I found the relation ID by googling for it (www.google.at/search?q=openstreetmap+relation+innsbruck).# get OSM datalibrary(osmar)library(maptools)innsbruck sp_innsbruck # convert to KMLfor( i in seq_along(sp_innsbruck) ) { ...

Read more »

Taxonomy with R: Exploring the Taxize-Package

December 16, 2012
By
Taxonomy with R: Exploring the Taxize-Package

First off, I'd really like to give a shout-out to the brave people who have created and maintain this great package - the fame is yours!So, while exploring the capabilities of the package some issues with the ITIS-Server arose and with large datasets things weren't working out quite well for me.I then...

Read more »