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 (http://wiki.openstreetmap.org/wiki/Osmosis/Detailed_Usage) 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)?
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!
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”)