1 class Node < ActiveRecord::Base
3 set_table_name 'current_nodes'
5 has_many :old_nodes, :foreign_key => :id
10 def self.from_xml(xml, create=false)
17 doc.find('//osm/node').each do |pt|
20 node.latitude = pt['lat'].to_f
21 node.longitude = pt['lon'].to_f
23 if node.latitude > 90 or node.latitude < -90 or node.longitude > 180 or node.longitude < -180
28 node.id = pt['id'].to_i
31 node.visible = pt['visible'] == '1'
34 node.timestamp = Time.now
36 node.timestamp = Time.parse(pt['timestamp'])
41 pt.find('tag').each do |tag|
42 tags << [tag['k'],tag['v']]
45 tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';')
46 tags = '' if tags.nil?
57 old_node = OldNode.from_node(this)
62 rescue Exception => ex
69 doc = XML::Document.new
71 doc.encoding = "UTF-8"
72 root = XML::Node.new 'osm'
73 root['version'] = '0.4'
74 root['generator'] = 'OpenStreetMap server'
76 el1 = XML::Node.new 'node'
77 el1['id'] = this.id.to_s
78 el1['lat'] = this.latitude.to_s
79 el1['lon'] = this.longitude.to_s
80 split_tags(el1, this.tags)
81 el1['visible'] = thiss.visible.to_s
82 el1['timestamp'] = this.timestamp.xmlschema
91 def split_tags(el, tags)
92 tags.split(';').each do |tag|
93 parts = tag.split('=')
96 key = parts[0].strip unless parts[0].nil?
97 val = parts[1].strip unless parts[1].nil?
98 if key != '' && val != ''