X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2006c416d293f9281a6524722f8c48badf7379b1..ff401e541b89850376e7491f98ec5f3c18057d9b:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index 4c99de2f1..789a5f439 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -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