| Class | OSM::API |
| In: |
lib/OSM/API.rb
|
| Parent: | Object |
The OSM::API class handles all calls to the OpenStreetMap API.
Usage:
require 'OSM/API' @api = OSM::API.new node = @api.get_node(3437)
In most cases you can use the more convenient methods on the OSM::Node, OSM::Way, or OSM::Relation objects.
| DEFAULT_BASE_URI | = | 'http://www.openstreetmap.org/api/0.5/' | the default base URI for the API |
Get all objects in the bounding box (bbox) given by the left, bottom, right, and top parameters. They will be put into a OSM::Database object which is returned.
# File lib/OSM/API.rb, line 125
125: def get_bbox(left, bottom, right, top)
126: raise TypeError.new('"left" value needs to be a number between -180 and 180') unless(left.kind_of?(Float) && left >= -180 && left <= 180)
127: raise TypeError.new('"bottom" value needs to be a number between -90 and 90') unless(bottom.kind_of?(Float) && bottom >= -90 && bottom <= 90)
128: raise TypeError.new('"right" value needs to be a number between -180 and 180') unless(right.kind_of?(Float) && right >= -180 && right <= 180)
129: raise TypeError.new('"top" value needs to be a number between -90 and 90') unless(top.kind_of?(Float) && top >= -90 && top <= 90)
130: response = get("map?bbox=#{left},#{bottom},#{right},#{top}")
131: check_response_codes(response)
132: db = OSM::Database.new
133: parser = OSM::StreamParser.new(:string => response.body, :db => db)
134: parser.parse
135: db
136: end
Get an object (‘node’, ‘way’, or ‘relation’) with specified ID from API.
# File lib/OSM/API.rb, line 61
61: def get_object(type, id)
62: raise ArgumentError.new("type needs to be one of 'node', 'way', and 'relation'") unless type =~ /^(node|way|relation)$/
63: raise TypeError.new('id needs to be a positive integer') unless(id.kind_of?(Fixnum) && id > 0)
64: response = get("#{type}/#{id}")
65: check_response_codes(response)
66: parser = OSM::StreamParser.new(:string => response.body, :callbacks => OSM::ObjectListCallbacks.new)
67: list = parser.parse
68: raise APITooManyObjects if list.size > 1
69: list[0]
70: end