Learn R Programming

tmap (version 1.2)

read_GPX: Read GPX file

Description

Read a GPX file. By default, it reads all possible GPX layers, and only returns shapes for layers that have any features.

Usage

read_GPX(file, layers = c("waypoints", "tracks", "routes", "track_points",
  "route_points"))

Arguments

file
a GPX filename (including directory)
layers
vector of GPX layers. Possible options are "waypoints", "tracks", "routes", "track_points", "route_points". By dedault, all those layers are read.

Value

  • for each defiend layer, a shape is returned (only if the layer has any features). If only one layer is defined, the corresponding shape is returned. If more than one layer is defined, a list of shape objects, one for each layer, is returned.

Examples

Run this code
### Demo to visualise the route of the Amstel Gold Race, a professional cycling race
	
# download data
tmpdir <- tempdir()
tmpfile <- tempfile()
download.file("http://www.gpstracks.nl/routes-fiets/f-limburg-amstel-gold-race-2014.zip", 
			  tmpfile, mode="wb")
unzip(tmpfile, exdir=tmpdir)

# read GPX file
AGR <- read_GPX(file.path(tmpdir, "f-limburg-amstel-gold-race-2014.gpx"))

# read OSM of Zuid-Limburg (take bounding box and extend it by 1.05)
ZLim <- read_osm(bb(AGR$tracks, ext=1.05))

# change route part names
levels(AGR$tracks$name) <- paste(c("First", "Second", "Third", "Final"), "loop")

# plot it
tm_shape(ZLim) + 
  tm_raster(saturation=.25) +
tm_shape(AGR$tracks) +
	tm_lines(col = "name", lwd = 4, title.col="Amstel Gold Race", palette="Dark2") + 
tm_shape(AGR$waypoints) +
	tm_bubbles(size=.1, col="gold", border.col = "black") + 
tm_text("name", size = .75, bg.color="white", bg.alpha=.25, auto.placement = .25) +
tm_legend(position=c("right", "top"), frame=TRUE, bg.color = "gold")

Run the code above in your browser using DataLab