]> git.openstreetmap.org Git - rails.git/blob - app/models/geo_record.rb
migration 013 removes tags from nodes and old nodes tables/ 014 does not do anything atm
[rails.git] / app / models / geo_record.rb
1 class GeoRecord < ActiveRecord::Base
2   before_save :update_tile
3
4   def self.find_by_area(minlat, minlon, maxlat, maxlon, options)
5     self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do
6       return self.find(:all, options)
7     end
8   end
9
10   def update_tile
11     self.tile = QuadTile.tile_for_point(lat, lon)
12   end
13
14   def lat=(l)
15     self.latitude = (l * 10000000).round
16   end
17
18   def lon=(l)
19     self.longitude = (l * 10000000).round
20   end
21
22   # Return WGS84 latitude
23   def lat
24     return self.latitude.to_f / 10000000
25   end
26
27   # Return WGS84 longitude
28   def lon
29     return self.longitude.to_f / 10000000
30   end
31
32   # fuck knows
33   def lon_potlatch(baselong,masterscale)
34     (self.lon-baselong)*masterscale+350
35   end
36
37   def lat_potlatch(basey,masterscale)
38     -(lat2y(self.lat)-basey)*masterscale+250
39   end
40   
41   private
42   
43   def lat2y(a)
44     180/Math::PI * Math.log(Math.tan(Math::PI/4+a*(Math::PI/180)/2))
45   end
46
47 end
48