# R: Streets of France

April 19, 2013
By

(This article was first published on Statistik Stuttgart » R, and kindly contributed to R-bloggers)

I was Inspired from Ben Frys all Streets project. There he plotted all streets of the United States of America (about 240 million segments). I tried this first for the countries in Europe, France has about 22 million segments, with the goal to get an all street map of Europe.

My data source originate from the OpenStreetMap project and was downloaded from the servers of Geofabrik. First step in the procedure was to convert the pbf-file to the o5m-file format by osmconvert:

osmconvert france.osm.pbf --out-o5m –o="france.o5m"


In the second step, I filtered all relevant streets with the osmfilter tool

osmfilter france.o5m --keep="highway=motorway =motorway_link =trunk
=service" --drop-author --drop-version > france_streets.osm


Similar as in the first step, this file is transformed to a osm-file format and by Quantum Gis into the ESRI-shapefile format. This ESRI-data file is now loaded into R.

The geom_segment function for plotting the lines was originares form the blog-post Great Maps with ggplot2. The function conv_sp_lines_to_seg converts the shp-data to lines described by two 2-dim points (start and end-point).

library(sp)
library(ggplot2)
library(maptools)
source("../convert_shp_line_to_seg.R")
source("../geom_segment2.R")

linesFrance <- conv_sp_lines_to_seg(shpFrance)
rm(shpFrance)

streets <- geom_segment2(data=linesFrance,
aes(xend=elon, yend=elat),
size=.025,
color="black")

p <- ggplot(linesFrance, aes(x=slon,y=slat)) +
streets +
scale_x_continuous("", breaks=NULL) +
scale_y_continuous("", breaks=NULL) +
theme(panel.background=element_rect(fill='#f5f4e0'))


I plotted this map on my notbook with 16GB RAM which is completely used at the rendering for the 22 million segments. It seems that for plotting Europe another solution has to be developed.