1 class OldNode < ActiveRecord::Base
4 validates_presence_of :user_id, :timestamp
5 validates_inclusion_of :visible, :in => [ true, false ]
6 validates_numericality_of :latitude, :longitude
7 validate :validate_position
11 before_save :update_tile
13 def self.find_by_area(minlat, minlon, maxlat, maxlon, options)
14 self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do
15 return self.find(:all, options)
20 self.tile = QuadTile.tile_for_point(lat, lon)
24 self.latitude = (l * 10000000).round
28 self.longitude = (l * 10000000).round
32 return self.latitude.to_f / 10000000
36 return self.longitude.to_f / 10000000
40 errors.add_to_base("Node is not in the world") unless in_world?
44 return false if self.lat < -90 or self.lat > 90
45 return false if self.lon < -180 or self.lon > 180
49 def self.from_node(node)
50 old_node = OldNode.new
51 old_node.latitude = node.latitude
52 old_node.longitude = node.longitude
53 old_node.visible = node.visible
54 old_node.tags = node.tags
55 old_node.timestamp = node.timestamp
56 old_node.user_id = node.user_id
62 el1 = XML::Node.new 'node'
63 el1['id'] = self.id.to_s
64 el1['lat'] = self.lat.to_s
65 el1['lon'] = self.lon.to_s
66 el1['user'] = self.user.display_name if self.user.data_public?
67 Node.split_tags(el1, self.tags)
68 el1['visible'] = self.visible.to_s
69 el1['timestamp'] = self.timestamp.xmlschema