Class: CartoCSSHelper::DataFileGenerator
- Inherits:
-
Object
- Object
- CartoCSSHelper::DataFileGenerator
- Defined in:
- lib/cartocss_helper/data_file_handling.rb
Instance Method Summary collapse
- #add_node(lat, lon, tags, id) ⇒ Object
- #add_tags(tags) ⇒ Object
- #add_way(tags, nodes, id) ⇒ Object
- #close_file ⇒ Object
- #finish_file ⇒ Object
- #generate ⇒ Object
- #generate_closed_way_topology(lat, lon, tags) ⇒ Object
- #generate_node_topology(lat, lon, tags) ⇒ Object
- #generate_prefix ⇒ Object
- #generate_sufix ⇒ Object
- #generate_way_topology(lat, lon, tags) ⇒ Object
-
#initialize(tags, type, lat, lon, size) ⇒ DataFileGenerator
constructor
A new instance of DataFileGenerator.
- #open_file ⇒ Object
- #prepare_file ⇒ Object
Constructor Details
#initialize(tags, type, lat, lon, size) ⇒ DataFileGenerator
Returns a new instance of DataFileGenerator.
45 46 47 48 49 50 51 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 45 def initialize(, type, lat, lon, size) @lat = lat @lon = lon @tags = @type = type @size = size end |
Instance Method Details
#add_node(lat, lon, tags, id) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 112 def add_node(lat, lon, , id) @data_file.write "\n" @data_file.write " <node id='#{id}' visible='true' lat='#{lat}' lon='#{lon}'>" () @data_file.write '</node>' end |
#add_tags(tags) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 130 def () .each do |tag| @data_file.write "\n" @data_file.write " <tag k='#{tag[0]}' v='#{tag[1]}' />" end end |
#add_way(tags, nodes, id) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 119 def add_way(, nodes, id) @data_file.write "\n" @data_file.write " <way id='#{id}' visible='true'>" nodes.each do |node| @data_file.write "\n" @data_file.write " <nd ref='#{node}' />" end () @data_file.write "\n </way>" end |
#close_file ⇒ Object
57 58 59 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 57 def close_file @data_file.close end |
#finish_file ⇒ Object
66 67 68 69 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 66 def finish_file generate_sufix close_file end |
#generate ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 71 def generate prepare_file if @type == 'node' generate_node_topology(@lat, @lon, @tags) elsif @type == 'way' generate_way_topology(@lat, @lon, @tags) elsif @type == 'closed_way' generate_closed_way_topology(@lat, @lon, @tags) else raise 'this type of element does not exists' end finish_file end |
#generate_closed_way_topology(lat, lon, tags) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 95 def generate_closed_way_topology(lat, lon, ) delta = @size / 3 add_node lat - delta, lon - delta, [], 1 add_node lat - delta, lon + delta, [], 2 add_node lat + delta, lon + delta, [], 3 add_node lat + delta, lon - delta, [], 4 add_way , [1, 2, 3, 4, 1], 5 end |
#generate_node_topology(lat, lon, tags) ⇒ Object
85 86 87 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 85 def generate_node_topology(lat, lon, ) add_node lat, lon, , 2387 end |
#generate_prefix ⇒ Object
104 105 106 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 104 def generate_prefix @data_file.write "<?xml version='1.0' encoding='UTF-8'?>\n<osm version='0.6' generator='script'>" end |
#generate_sufix ⇒ Object
108 109 110 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 108 def generate_sufix @data_file.write "\n</osm>" end |
#generate_way_topology(lat, lon, tags) ⇒ Object
89 90 91 92 93 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 89 def generate_way_topology(lat, lon, ) add_node lat, lon - @size / 3, [], 1 add_node lat, lon + @size / 3, [], 2 add_way , [1, 2], 3 end |
#open_file ⇒ Object
53 54 55 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 53 def open_file @data_file = open(Configuration.get_data_filename, 'w') end |
#prepare_file ⇒ Object
61 62 63 64 |
# File 'lib/cartocss_helper/data_file_handling.rb', line 61 def prepare_file open_file generate_prefix end |