4 # Ensure that when coordinates are printed that they are always in decimal degrees,
6 # Unfortunately you can't extend Numeric classes directly (e.g. `Coord < Float`).
7 class Coord < DelegateClass(Float)
17 # This scaling factor is used to convert between the float lat/lon that is
18 # returned by the API, and the integer lat/lon equivalent that is stored in
22 def self.included(base)
23 base.scope :bbox, ->(bbox) { base.where(OSM.sql_for_area(bbox)) }
24 base.before_save :update_tile
27 # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
28 # * returns true/false
30 return false if lat < -90 || lat > 90
31 return false if lon < -180 || lon > 180
36 self.tile = QuadTile.tile_for_point(lat, lon)
40 self.latitude = (l * SCALE).round
44 self.longitude = (l * SCALE).round
47 # Return WGS84 latitude
49 Coord.new(latitude.to_f / SCALE)
52 # Return WGS84 longitude
54 Coord.new(longitude.to_f / SCALE)