2 # This scaling factor is used to convert between the float lat/lon that is
3 # returned by the API, and the integer lat/lon equivalent that is stored in
7 def self.included(base)
8 base.extend(ClassMethods)
15 # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
16 # * returns true/false
18 return false if self.lat < -90 or self.lat > 90
19 return false if self.lon < -180 or self.lon > 180
24 self.tile = QuadTile.tile_for_point(lat, lon)
28 self.latitude = (l * SCALE).round
32 self.longitude = (l * SCALE).round
35 # Return WGS84 latitude
37 return self.latitude.to_f / SCALE
40 # Return WGS84 longitude
42 return self.longitude.to_f / SCALE
45 # Generic checks that are run for the updates and deletes of
46 # node, ways and relations. This code is here to avoid duplication,
47 # and allow the extention of the checks without having to modify the
48 # code in 6 places. This will throw an exception if there is an inconsistency
49 def check_consistency(old, new, user)
50 if new.version != old.version
51 raise OSM::APIVersionMismatchError.new(new.version, old.version)
52 elsif new.changeset.user_id != user.id
53 raise OSM::APIUserChangesetMismatchError.new
54 elsif not new.changeset.is_open?
55 raise OSM::APIChangesetAlreadyClosedError.new
61 180/Math::PI * Math.log(Math.tan(Math::PI/4+a*(Math::PI/180)/2))
65 def find_by_area(minlat, minlon, maxlat, maxlon, options)
66 self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do
67 return self.find(:all, options)