0
@@ -31,17 +31,110 @@ features = ARGV
0
-
input_doc = Document.file(input)
0
+
$input_doc = Document.file(input)
0
# Create new XML doc for output
0
-
output_doc = Document.new
0
+
$output_doc = Document.new
0
#output_doc << input_doc.xml_decl
0
#output_doc.root = input_doc.root
0
#output_doc.root['generator'] = "osm-cherrypick"
0
-output_doc.root = Node.new('osm')
0
-output_doc.root['version'] = '0.5'
0
-output_doc.root['generator'] = 'osm-cherrypick'
0
+$output_doc.root = Node.new('osm')
0
+$output_doc.root['version'] = '0.5'
0
+$output_doc.root['generator'] = 'osm-cherrypick'
0
+ $input_doc.find("node[@id='#{id}']").each do |node|
0
+ #puts "Node id: #{the_node['id']}"
0
+ # Add the feature to the output doc
0
+ $output_doc.root.child_add(node)
0
+ $input_doc.find("way[@id='#{id}']").each do |way|
0
+ #puts "Node id: #{the_node['id']}"
0
+ # Add the feature to the output doc
0
+ way.find("nd").each do |node|
0
+ #puts "Node ref in way: #{node['ref']}"
0
+ # Get the feature from the file
0
+ extract_node(node['ref'])
0
+ #$input_doc.find("node[@id='#{node['ref']}']").each do |the_node|
0
+ #puts "Node id: #{the_node['id']}"
0
+ # Add the feature to the output doc
0
+ #$output_doc.root.child_add(the_node)
0
+ $output_doc.root.child_add(way)
0
+def extract_relation(id)
0
+ $input_doc.find("relation[@id='#{id}']").each do |relation|
0
+ relation.find("member").each do |member|
0
+ extract_node(member['ref'])
0
+ extract_way(member['ref'])
0
+ extract_relation(member['ref'])
0
+ puts "Bad shit happened!"
0
+ $output_doc.root.child_add(relation)
0
+def extract_nodes(key, value)
0
+ $input_doc.find("/osm/node/tag[@k='#{key}' and @v='#{value}']/..").each do |node|
0
+ # Add the feature to the output doc
0
+ #extract_node(node['id'])
0
+ $output_doc.root.child_add(node)
0
+ #puts "Node id: #{node['id']}"
0
+def extract_ways(key, value)
0
+ # Get the feature from the file
0
+ $input_doc.find("/osm/way/tag[@k='#{key}' and @v='#{value}']/..").each do |way|
0
+ #puts "Way id: #{way['id']}"
0
+ # Add the feature to the output doc
0
+ way.find("nd").each do |node|
0
+ #puts "Node ref in way: #{node['ref']}"
0
+ # Get the feature from the file
0
+ extract_node(node['ref'])
0
+ #$input_doc.find("node[@id='#{node['ref']}']").each do |the_node|
0
+ #puts "Node id: #{the_node['id']}"
0
+ # Add the feature to the output doc
0
+ #$output_doc.root.child_add(the_node)
0
+ $output_doc.root.child_add(way)
0
+def extract_relations(key, value)
0
+ $input_doc.find("/osm/relation/tag[@k='#{key}' and @v='#{value}']/..").each do |relation|
0
+ relation.find("member").each do |member|
0
+ extract_node(member['ref'])
0
+ extract_way(member['ref'])
0
+ extract_relation(member['ref'])
0
+ puts "Bad shit happened!"
0
+ $output_doc.root.child_add(relation)
0
for feature in features do
0
@@ -51,30 +144,11 @@ for feature in features do
0
# Get the feature from the file
0
- input_doc.find("/osm/#{type}/tag[@k='#{key}' and @v='#{value}']/..").each do |node|
0
- # Add the feature to the output doc
0
- output_doc.root.child_add(node)
0
- #puts "Node id: #{node['id']}"
0
+ extract_nodes(key, value)
0
- #puts "Ways are not supported yet!"
0
- # Get the feature from the file
0
- input_doc.find("#{type}/tag[@k='#{key}' and @v='#{value}']/..").each do |way|
0
- #puts "Way id: #{way['id']}"
0
- # Add the feature to the output doc
0
- way.find("nd").each do |node|
0
- #puts "Node ref in way: #{node['ref']}"
0
- # Get the feature from the file
0
- input_doc.find("node[@id='#{node['ref']}']").each do |the_node|
0
- #puts "Node id: #{the_node['id']}"
0
- # Add the feature to the output doc
0
- output_doc.root.child_add(the_node)
0
- output_doc.root.child_add(way)
0
+ extract_ways(key, value)
0
-
puts "Relations are not supported yet!"0
+
extract_relations(key, value)0
puts "Wrong type of object: #{feature}"
0
# Write XML doc to the output file
0
-output_doc.save(output, format)
0
+$output_doc.save(output, format)
Comments
No one has commented yet.