# Where have I been in 2015

Hier ein weiterer meiner Jahresrückblick 2015-Posts. Die anderen sind unter dem Tag jahresrückblick15 zu finden.

Weil das letzte Mal schon auf Englisch, hier grad wieder.

I’ve updated the RMarkdown-document of the “analysis” of my yearly Geodata a bit. Namely, I parametrized the shizzle out of it, switched to the freely available Stamen maps (based on OpenStreetMap data) and - something which I’m quite prowd of myself - implemented a function to automagically extract the name of a location based on its latitude and longitude from the GeoNames database.

The original file with the full code can be found either on GitHub or on RPubs, the result is pasted below.

# Introduction

I tracked my location data with OpenPaths since the beginning of 2014. OpenPaths comes as an application for your phone, which tracks its location, uploads it to the OpenPath servers. You can then donate your data for scientific research and also look at the data yourself, which is what we do here.

To be able to do this, we grab a .CSV file with the location data. Log in to OpenPaths, and click on CSV under Download my data, which gives you a comma separated list of your location data, which can then visualize with R, which is what we’ve done here.

# Data

We want to plot the location points on a map, which we can do with the wonderful ggmap library. To get the place names from the GeoNames Web Services, we need the RCurl library, to parse the output XML, we obviously need the XML library.

First, we load the data file and then remove all the datapoints where we have an altitudes of ‘0’ (which is probably a fluke in the GPS data) Obviously, we only want to look at this years data, we thus save a subset of the dataset for further processing.

[code lang=r] library(ggmap) library(RCurl) library(XML) data <- read.csv(“/Users/habi/Dev/R/openpaths_habi.csv”) data$alt[data$alt == 0] <- NA whichyear <- 2015 thisyear <- subset(data, grepl(whichyear, data$date)) [/code] Since we’re going to use it often, we’re making a function to grab the name of a place based on its latitude and longitude. [code lang=r] geoname <- function(lat,lon){ # Grab GeoNames XML from their API, according to location txt = getURL(paste0(“http://api.geonames.org/findNearbyPostalCodes?lat=", lat, “&lng=“, lon, “&username=habi”, collabse = NULL), .encoding = “UTF-8”, .mapUnicode = TRUE) # Parse XML tree xmldata <- htmlTreeParse(txt, asText=TRUE) # Extract node (with empirically found location) Name <- xmldata$children[[2]][[1]][[1]][[1]][[2]][[1]] # Since we”re only using the name as string, we can return it as such return(unlist(Name)[[2]]) } [/code]

Then, we display a summary of the geographical points.

[code lang=text]

[/code]

[code lang=text]

## 0 8290

[/code]

We see that in 2015 I have only used one phone, my iPhone 5S (iPhone6,2) and went through 9 different iOS version numbers.