Class: OpenStreetMap::Node

Inherits:
Element
  • Object
show all
Defined in:
lib/open_street_map/node.rb

Overview

OpenStreetMap Node.

To create a new OpenStreetMap::Node object:

node = OpenStreetMap::Node.new(:id => "123", :lat => "52.2", :lon => "13.4", :changeset => "12", :user => "fred", :uid => "123", :visible => true, :timestamp => "2005-07-30T14:27:12+01:00")

To get a node from the API:

node = OpenStreetMap::Node.find(17)

Instance Attribute Summary collapse

Attributes inherited from Element

#changeset, #id, #tags, #timestamp, #uid, #user, #version

Instance Method Summary collapse

Methods inherited from Element

#[], #[]=, #add_tags, #attributes, from_api, #get_history_from_api, #get_relations_from_api, #initialize_copy, #is_tagged?, #method_missing, #shape, #update_attributes

Constructor Details

#initialize(attrs = {}) ⇒ Node

Create new Node object.

If id is nil a new unique negative ID will be allocated.



24
25
26
27
28
29
# File 'lib/open_street_map/node.rb', line 24

def initialize(attrs = {})
  attrs.stringify_keys!
  @lon = attrs['lon'].to_f rescue nil
  @lat = attrs['lat'].to_f rescue nil
  super(attrs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OpenStreetMap::Element

Instance Attribute Details

#latObject

Latitude in decimal degrees



16
17
18
# File 'lib/open_street_map/node.rb', line 16

def lat
  @lat
end

#lonObject

Longitude in decimal degrees



13
14
15
# File 'lib/open_street_map/node.rb', line 13

def lon
  @lon
end

Instance Method Details

#attribute_listObject

List of attributes for a Node



36
37
38
# File 'lib/open_street_map/node.rb', line 36

def attribute_list
  [:id, :version, :uid, :user, :timestamp, :lon, :lat, :changeset]
end

#to_xml(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/open_street_map/node.rb', line 40

def to_xml(options = {})
  xml = options[:builder] ||= Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  xml.osm do
    xml.node(attributes) do
      tags.to_xml(:builder => xml, :skip_instruct => true)
    end
  end
end

#typeObject



31
32
33
# File 'lib/open_street_map/node.rb', line 31

def type
  'Node'
end