R: Streets of France

April 19, 2013

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

Frankreich_ThumbI 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
=trunk_link =primary =primary_link =secondary =secondary_link =tertiary
=tertiary_link =living_street =pedestrian =residential =unclassified
=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).


shpFrance <- readShapeLines("france.shp")
linesFrance <- conv_sp_lines_to_seg(shpFrance)

streets <- geom_segment2(data=linesFrance,
                         aes(xend=elon, yend=elat),

p <- ggplot(linesFrance, aes(x=slon,y=slat)) +
  streets +
  scale_x_continuous("", breaks=NULL) +
  scale_y_continuous("", breaks=NULL) +

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.

To leave a comment for the author, please follow the link and comment on his blog: Statistik Stuttgart » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.