Wednesday, August 1, 2018
Make a KML File from an OpenStreetMap Trail
Make a KML File from an OpenStreetMap Trail
Ever wished to use a trail on OSM on your GPS or smartphone? With this neat little R-Script this can easily be done. Youll just need to search OpenStreetMap for the ID of the trail (way), put this as argument to osmar::get_osm, convert to KML and youre good to go!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8tt2N-TpkeOJTPG5KXnKP8PNi-1VY8kUI520BapP0Xm0nJ0ZxNq_U2FE1E4Cevh_pvtAIPeFS3U-0kZA4oNfR885SqNOgulFXUS3BeF2I4X9rfLLFaIzgjkFUp2lMEM6pEyEY7LMoURZ7/s320/way_osm.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioBHiIudb-BWsXAIC28YQim7sm4SxUKbW07dLZ3NzSJmrGBr1vjVwYmOYQPsjRfnk3EyD0DqA5Pfal8fy-uvkx11zA4-m5ypCT81RhR3nNLSVQ-lAV9EUKuFBrTz8OrsQoYVRhutyfdVlQ/s320/osm_kml.jpg)
# get OSM data
library(osmar)
library(maptools)
rotewandsteig <- get_osm(way(166274005), full = T)
sp_rotewandsteig <- as_sp(rotewandsteig, what = "lines")
# convert to KML
kmlLine(sp_rotewandsteig@lines[[1]], kmlfile = "rotewandsteig.kml",
lwd = 3, col = "blue", name = "Rotewandsteig")
# view it
shell.exec("rotewandsteig.kml")