R: Streets of France

[This article was first published on Statistik Stuttgart » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog: Statistik Stuttgart » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)