5urpher
10/15/2016 - 3:32 PM

R scripts to rip ways out of OSM and into Google Earth.

Theses are the R scripts I use to rip ways from Openstreetmap, and open them in Google Earth.

Required packages. bitops geosphere maptools osmar RCurl rgeos sp

source: http://thebiobucket.blogspot.co.uk/2014/09/make-kml-file-from-openstreetmap-trail.html

# get OSM data
library(osmar)
library(maptools)

way_id <- 384632079

railroad <- get_osm(way(way_id), full = T)
sp_railroad <- as_sp(railroad, what = "lines")

# convert to KML 
kmlLine(sp_railroad@lines[[1]], kmlfile = "railroad.kml", lwd = 2, col = "#000000FF", name = way_id) 

# view it
shell.exec("railroad.kml")
# get OSM data
library(osmar)
library(maptools)

way_id <- 301227024

powerline <- get_osm(way(way_id), full = T)
sp_powerline <- as_sp(powerline, what = "lines")

# convert to KML 
kmlLine(sp_powerline@lines[[1]], kmlfile = "powerline.kml", lwd = 2, col = "#00AAFFFF", name = way_id) 

# view it
shell.exec("powerline.kml")
# get OSM data
library(osmar)
library(maptools)

way_id <- 24469298

tramline <- get_osm(way(way_id), full = T)
sp_tramline <- as_sp(tramline, what = "lines")

# convert to KML 
kmlLine(sp_tramline@lines[[1]], kmlfile = "tramline.kml", lwd = 2, col = "#670011FF", name = way_id) 

# view it
shell.exec("tramline.kml")