]> git.openstreetmap.org Git - rails.git/blobdiff - lib/osm.rb
add ability to specify custom background in the query string
[rails.git] / lib / osm.rb
index 4c99de2f144e8f111e0bce5c719c015b2409185d..f36deb0a80906fa185e3c62764727c29604fb436 100644 (file)
@@ -187,18 +187,18 @@ module OSM
   # Raised when a way has more than the configured number of way nodes.
   # This prevents ways from being to long and difficult to work with
   class APITooManyWayNodesError < APIError
-    def initialize(provided, max)
-      @provided, @max = provided, max
+    def initialize(id, provided, max)
+      @id, @provided, @max = id, provided, max
     end
     
-    attr_reader :provided, :max
+    attr_reader :id, :provided, :max
 
     def status
       :bad_request
     end
     
     def to_s
-      "You tried to add #{provided} nodes to the way, however only #{max} are allowed"
+      "You tried to add #{provided} nodes to way #{id}, however only #{max} are allowed"
     end
   end
 
@@ -218,6 +218,22 @@ module OSM
     end
   end
 
+  ##
+  # raised when bounding box is invalid
+  class APIBadBoundingBox < APIError
+    def initialize(message)
+      @message = message
+    end
+
+    def status
+      :bad_request
+    end
+
+    def to_s
+      @message
+    end
+  end
+
   ##
   # raised when an API call is made using a method not supported on that URI
   class APIBadMethodError < APIError
@@ -318,6 +334,11 @@ module OSM
       maxlon = (@lon + lonradius) * 180 / PI
       return { :minlat => minlat, :maxlat => maxlat, :minlon => minlon, :maxlon => maxlon }
     end
+
+    # get the SQL to use to calculate distance
+    def sql_for_distance(lat_field, lon_field)
+      "6372.795 * 2 * asin(sqrt(power(sin((radians(#{lat_field}) - #{@lat}) / 2), 2) + cos(#{@lat}) * cos(radians(#{lat_field})) * power(sin((radians(#{lon_field}) - #{@lon})/2), 2)))"
+    end
   end
 
   class GeoRSS