1 class GeoRecord < ActiveRecord::Base
2 before_save :update_tile
4 # This is a scaling factor for going between the lat and lon via the API
5 # and the longitude and latitude that is stored in the database
8 # Is this node within -90 <= latitude <= 90 and -180 <= longitude <= 180
11 return false if self.lat < -90 or self.lat > 90
12 return false if self.lon < -180 or self.lon > 180
16 def self.find_by_area(minlat, minlon, maxlat, maxlon, options)
17 self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do
18 return self.find(:all, options)
23 self.tile = QuadTile.tile_for_point(lat, lon)
27 self.latitude = (l * SCALE).round
31 self.longitude = (l * SCALE).round
34 # Return WGS84 latitude
36 return self.latitude.to_f / SCALE
39 # Return WGS84 longitude
41 return self.longitude.to_f / SCALE
44 # Potlatch projections
45 def lon_potlatch(baselong,masterscale)
46 (self.lon-baselong)*masterscale
49 def lat_potlatch(basey,masterscale)
50 -(lat2y(self.lat)-basey)*masterscale
56 180/Math::PI * Math.log(Math.tan(Math::PI/4+a*(Math::PI/180)/2))