Planet.osm to text
| This article or section may contain out-of-date information. The information is no longer correct, or no longer has relevance. If you know about the current state of affairs, please help keep everyone informed by updating this information. (Discuss) |
Contents |
Introduction
This is a perl script to convert Planet.osm into text-files.
Planet.osm is a XML file containing OpenStreetMap's output data. While many programs can use it directly, it can be quite slow and memory-intensive to parse, often overwhelming the more naïve XML implementations.
Text files are fast, human-readable, and the native file format for most operating systems and programming languages. So having OpenStreetMap data in text format can be useful.
Source code
Usage
Save source code as convert.pl, and type:
perl convert.pl planet.osm
Output files
osm.txt
List of segments
- Latitude (start)
- Longitude (start)
- Latitude (end)
- Longitude (end)
- Class
- Name
- Highway type
Sample:
50.914915,-1.400628,50.915200,-1.399410,residential,, 50.915200,-1.399410,50.917200,-1.400710,residential,Dover Street, 50.917200,-1.400710,50.916900,-1.402500,residential,Mordaunt Road, 51.875281,-1.363597,51.875334,-1.361666,minor,, 51.868922,-1.377673,51.869134,-1.377072,secondary,B4437,
Currently osm.txt is 26MB (approx 20MB of lat/long + 6MB of text)
points.txt
List of nodes with interesting attributes
- Latitude
- Longitude
- Name
- Amenity
- Class
Sample:
51.086900,-1.267740,Chestnut Horse,,pub 51.090600,-1.254090,Chilland,,hamlet 51.085900,-1.271710,Cricketers,,pub 51.087800,-1.274500,EAS CH,,church 51.086400,-1.271930,Easton,,village 52.554483,-1.828250,Beeches Walk Post Office,post_office,
Currently points.txt is 627KB, and could be reduced if things with "class=node" were filtered-out
ways.txt
Temporary debug file
stats.txt
List of data statistics on the data encountered
Notes
Tags associated with a way overwrite any tags associated with the segments that are part of that way
Performance
4 minutes 7 seconds of computing time to convert the 2006-04 version of Planet.osm into text files, on a 700MHz/256MB PC
Bugs, TODO
- Slower than necessary when loading sparse datasets
- Weird results when node IDs are negative in the OSM file
- Should handle railways, waterways etc., as well as highways
- Put requests here