Class: OSMFile
- Inherits:
-
Object
- Object
- OSMFile
- Defined in:
- lib/fixosm/osm_file.rb
Instance Method Summary collapse
- #fix_and_save(output_file_path) ⇒ Object
- #open(input_file_path) ⇒ Object
- #sorted_nodes(tagname) ⇒ Object
Instance Method Details
#fix_and_save(output_file_path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fixosm/osm_file.rb', line 17 def fix_and_save(output_file_path) output_doc = Nokogiri::XML::Document.new osm_element = output_doc.add_child("<osm></osm>") sorted_nodes("node").each do |node| osm_element.add_child(node) end sorted_nodes("way").each do |node| osm_element.add_child(node) end sorted_nodes("relation").each do |node| osm_element.add_child(node) end output_file = File.open(output_file_path, 'w') output_file.puts output_doc.to_s output_file.close end |
#open(input_file_path) ⇒ Object
4 5 6 7 8 |
# File 'lib/fixosm/osm_file.rb', line 4 def open(input_file_path) input_file = File.open(input_file_path) @input_doc = Nokogiri::XML(input_file) input_file.close end |
#sorted_nodes(tagname) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/fixosm/osm_file.rb', line 10 def sorted_nodes(tagname) unsorted_nodes = @input_doc.xpath("//#{tagname}") unsorted_nodes.sort_by do |node| node.attr("id").to_i end end |