Blog Archives

Text Mining with R – Comparing Word Counts in two Text Documents

August 19, 2013
By

Here's what I came up with to compare word counts in two pieces of text. If you got any idea, I'd love to learn about alternatives!## a function that compares word counts in two textswordcount ...

Read more »

Spatial Overlays with R – Retrieving Polygon Attributes for a Set of Points

June 19, 2013
By

A short tutorial for spatial overlays using R-GIS..library(sp)library(dismo)# spatial dataalt gadm # viewplot(alt)plot(gadm, add=T)# some addressespts # make it spatialcoords spdf_pts # assign CRS/projectionproj4string(spdf_pts) # check datastr(spdf_pts)# plot it on topplot(spdf_pts, cex = 2, col = 2, add = T)# do an intersection (points in polygon)# yielding the polygon's attribute dataover(spdf_pts, gadm)

Read more »

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 »