GPX overview: An R function to create an overview of your .gpx files (using leaflet a

المشرف العام

Administrator
طاقم الإدارة
Why GPX? For what?

It's convenient to record tracks of your hiking/field trips with the GPS of your smartphone, tablet or just GPS as .gpx files. You can use them to georeference your pictures (for example with the great georefencer of Digikam) or use them for any kind of mapping purpose. I'm mainly using Maverick (and sometimes the Offline Logger ) to do that, Maverick creates files named with the form "2015-08-26 @ 11-31-59.gpx", therefore I'm quickly collecting a large amount of such files.

Well, the name helps to find when the .gpx file was created but what if I want to find such a file made a long time ago? It's easy to open them one by one, with QGIS for example, and check what's inside, but if I don't remember the exact date of the file it can become a pain in the ass to find what I'm looking for.

That's why I decided to write an R script creating a map with an overview of the recorded track, that I can run over a (long) list of files automatically. I started to write a short script using RgoogleMaps package producing, for each .gpx file, a map with the same name as the .gpx source. As a result, I get two folders, with the same number of files, one with all the .gpx and the second with all the .png maps, with corresponding names. Very convenient to browse through map overviews and find the GPS tracks I was seeking for.

Corresponding gpx tracks and png maps


However, in some case when a track includes very distant regions, the map is hard to read because of the large scale. This was the weakness of static maps and leaflet seemed to be the solution to easily make interactive maps that I can zoom/unzoom.
I adapted my script to include such a map into an .html file and I kept the static maps with different scales and backgrounds. As decorations for these maps, the script determines the first and last point's adresses and add it in the html, thanks to the reverse geocoding possibilities provided by the nice function reverseGeoCode() (J. Aswani, “All Things R: Geocode and reverse geocode your data using, R, JSON and Google Maps’ Geocoding API,” All Things R, 20-Mar-2012).
My function gives two kind of outputs: single .png map, a knitted .html page providing all details or both.
The way to decide which .gpx files to describe is rather flexible but partly associated with the way I organized the files on my comp. You may want to change this part for your own need.

And voilà for the context and the idea! It works like a charm, it takes a piece of time because I'm recalculating the speed of each (couple of) points... Well I know, speed is usually included inside of the .gpx attribute table, but I wanted to double check it. Just remove this part of the script if you want a faster process.

The .R code with the main function and the .Rmd code for knitting, are available on this GitHub repository. You're welcome to branch your improvements!

Let's describe how the function works.
Here we go!


File: 20150721_Apercu-GPX_Complet.R
Clean up and load libraries

rm(list=ls())library(RgoogleMaps)library(rgdal)library(knitr)library(leaflet)Function 'reverseGeoCode()' of J. Aswani.

reverseGeoCode
 
أعلى