From OpenStreetMap Wiki
Jump to: navigation, search

OSM-Data is an old ruby library öpcated in subversion path util/osm-data/lib for easier handling with the osm data objects. I extracted this from little-osm.

It is currently used in little-osm, the testserver.rb script and planet2mysql.rb

To use it, include the util/osm-data/lib directory to your include path and then require "osm/data" or "osm/rexml" (if you want to/from XML support). Look for one of the scripts mentioned above for an example.

Some examples:

node = Node.new :id => 23, :lat => 51, :lon => 11, :timestamp => Time.now
puts node.to_xml # prints: <node id='23' lat='51' lon='11' />
puts node.to_uid # prints an id, that is unique among all osm 
                 # primitives, not only all nodes
node["name"] = "Baker Street" # access to tags via []
puts node.timestamp  # prints the creation time

Documentation can be generated by calling to "rdoc" within the osm-data subdirectory.