]> git.openstreetmap.org Git - rails.git/blob - lib/map_boundary.rb
Added tests for changeset upload code. Refactored diff reading code and put it into...
[rails.git] / lib / map_boundary.rb
1 module MapBoundary
2   def sanitise_boundaries(bbox)
3     min_lon = [bbox[0].to_f,-180].max
4     min_lat = [bbox[1].to_f,-90].max
5     max_lon = [bbox[2].to_f,+180].min
6     max_lat = [bbox[3].to_f,+90].min
7
8     return min_lon, min_lat, max_lon, max_lat
9   end
10
11   def check_boundaries(min_lon, min_lat, max_lon, max_lat)
12     # check the bbox is sane
13     unless min_lon <= max_lon
14       raise("The minimum longitude must be less than the maximum longitude, but it wasn't")
15     end
16     unless min_lat <= max_lat
17       raise("The minimum latitude must be less than the maximum latitude, but it wasn't")
18     end
19     unless min_lon >= -180 && min_lat >= -90 && max_lon <= 180 && max_lat <= 90
20       # Due to sanitize_boundaries, it is highly unlikely we'll actually get here
21       raise("The latitudes must be between -90 and 90, and longitudes between -180 and 180")
22     end
23
24     # check the bbox isn't too large
25     requested_area = (max_lat-min_lat)*(max_lon-min_lon)
26     if requested_area > APP_CONFIG['max_request_area']
27       raise("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s + 
28         ", and your request was too large. Either request a smaller area, or use planet.osm")
29     end
30   end
31 end