2 # Take an array of length 4, and return the min_lon, min_lat, max_lon and
3 # max_lat within their respective boundaries.
4 def sanitise_boundaries(bbox)
5 min_lon = [[bbox[0].to_f,-180].max,180].min
6 min_lat = [[bbox[1].to_f,-90].max,90].min
7 max_lon = [[bbox[2].to_f,+180].min,-180].max
8 max_lat = [[bbox[3].to_f,+90].min,-90].max
9 return min_lon, min_lat, max_lon, max_lat
12 def check_boundaries(min_lon, min_lat, max_lon, max_lat, limit_small_area = :true)
13 # check the bbox is sane
14 unless min_lon <= max_lon
15 raise OSM::APIBadBoundingBox.new("The minimum longitude must be less than the maximum longitude, but it wasn't")
17 unless min_lat <= max_lat
18 raise OSM::APIBadBoundingBox.new("The minimum latitude must be less than the maximum latitude, but it wasn't")
20 unless min_lon >= -180 && min_lat >= -90 && max_lon <= 180 && max_lat <= 90
21 # Due to sanitize_boundaries, it is highly unlikely we'll actually get here
22 raise OSM::APIBadBoundingBox.new("The latitudes must be between -90 and 90, and longitudes between -180 and 180")
25 return unless limit_small_area == :true
27 # check the bbox isn't too large
28 requested_area = (max_lat-min_lat)*(max_lon-min_lon)
29 if requested_area > MAX_REQUEST_AREA
30 raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + MAX_REQUEST_AREA.to_s +
31 ", and your request was too large. Either request a smaller area, or use planet.osm")