Road Density Data

Dear all,
I am very new to OpenStreetMap and everything GIS-related in general, and would very much appreciate your advice to get me started in the right direction.

My goal is to obtain estimates of road density (km of roads per sq km of land) for a given area of the world. The outcome would be something like this:

Or this:

The actual format of the map is irrelevant–I only need the raw data for further analysis. So ideally, I would in the end obtain a csv file with columns “country, centroidLocation, RoadDensity”.
I would very much appreciate it if someone could help me started with this. Is the best way to write a Java script to parse the osm data (in which case, what is the best way to proceed)? Would Osmosis ( be of any use? Or is it better to use a GIS software (e.g., Qgis)? Are there better ways? Does anyone already have scripts to do something similar (obtain density by lat/longitude from raw osm data)?

Thank you so much!

I’d be interested in seeing the same thing. PostGIS can certainly do this, and I’m sure someone smarter than me can produce one line which does so using ST_Length. I don’t believe Osmosis has anything to help with finding the lengths of roads, but you certainly might use it to cut a chunk out of the Planet.osm file (or other extract). You could also use Python and OGR to create a script which goes over a grid, computing the total lengths for each section. If you get something working, please consider sharing your code and the results!

There have been several research projects comparing road lengths in gridded squares from OSM and other sources. The most recent of these is for Florida:

Great, thank you very much for pointing me in the right direction. I ended up using a combination of a java script to parse the OSM data (extract roads, etc) and then R to produce heat plots. For anyone interested, the R script goes as follows (roads.csv is the output from parsing the osm data):


Get the data and format it according to sp and spatstat formats

roads ← read.csv(‘dataProcessing/ScriptsToParseOSMdata/roads.csv’)
coords ← SpatialPoints(roads[, c(“lon”,“lat”)]) #lon and lat are the names of my lon/lat variables
roads1 ← SpatialPointsDataFrame(coords,roads)
roads.ppp ← as(coords,“ppp”)

Calculate and plot density

k025 ← density(roads.ppp, sigma=0.0015)
plot(as(roads1, “Spatial”), axes=T) #an empty frame . Optional
plot(k025, add=T)

A great help was: (lecture notes at the bottom)

Thanks and best,