Class: TilesCollection
- Inherits:
-
Object
- Object
- TilesCollection
- Defined in:
- lib/tiler/tiles.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#source ⇒ Object
Returns the value of attribute source.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
- #all ⇒ Object
- #cleanup ⇒ Object
- #columns ⇒ Object
- #create_temp_dir ⇒ Object
- #delete_temp_dir ⇒ Object
- #download ⇒ Object
- #flatten ⇒ Object
-
#initialize(args) ⇒ TilesCollection
constructor
A new instance of TilesCollection.
- #rows ⇒ Object
- #save_tile(x, y, tile) ⇒ Object
- #save_tiles ⇒ Object
- #stitch ⇒ Object
- #tile(x, y) ⇒ Object
Constructor Details
#initialize(args) ⇒ TilesCollection
Returns a new instance of TilesCollection.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tiler/tiles.rb', line 6 def initialize(args) @zoom = args[:zoom] @source = args[:source] || "sattelite" @start_x = args[:start_x] @start_y = args[:start_y] @end_x = args[:end_x] @end_y = args[:end_y] @output = args[:output] save_tiles end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
3 4 5 |
# File 'lib/tiler/tiles.rb', line 3 def dir @dir end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
4 5 6 |
# File 'lib/tiler/tiles.rb', line 4 def end @end end |
#output_file ⇒ Object
Returns the value of attribute output_file.
3 4 5 |
# File 'lib/tiler/tiles.rb', line 3 def output_file @output_file end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/tiler/tiles.rb', line 3 def source @source end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
4 5 6 |
# File 'lib/tiler/tiles.rb', line 4 def start @start end |
#zoom ⇒ Object
Returns the value of attribute zoom.
3 4 5 |
# File 'lib/tiler/tiles.rb', line 3 def zoom @zoom end |
Instance Method Details
#all ⇒ Object
29 30 31 |
# File 'lib/tiler/tiles.rb', line 29 def all @tiles end |
#cleanup ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/tiler/tiles.rb', line 70 def cleanup flatten.each do |tile| tile.file.close tile.file.unlink end delete_temp_dir end |
#columns ⇒ Object
25 26 27 |
# File 'lib/tiler/tiles.rb', line 25 def columns @start_x.upto(@end_x) end |
#create_temp_dir ⇒ Object
56 57 58 |
# File 'lib/tiler/tiles.rb', line 56 def create_temp_dir @dir = Dir.mktmpdir end |
#delete_temp_dir ⇒ Object
61 62 63 |
# File 'lib/tiler/tiles.rb', line 61 def delete_temp_dir FileUtils.remove_entry_secure dir if dir end |
#download ⇒ Object
65 66 67 68 |
# File 'lib/tiler/tiles.rb', line 65 def download create_temp_dir flatten.each{ |tile| tile.download(dir) } end |
#flatten ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/tiler/tiles.rb', line 33 def flatten rows.map do |y| columns.map do |x| tile(x,y) end end.flatten end |
#rows ⇒ Object
21 22 23 |
# File 'lib/tiler/tiles.rb', line 21 def rows @start_y.upto(@end_y) end |
#save_tile(x, y, tile) ⇒ Object
41 42 43 44 |
# File 'lib/tiler/tiles.rb', line 41 def save_tile(x,y,tile) @tiles[y] = {} unless @tiles[y] @tiles[y][x] = tile end |
#save_tiles ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/tiler/tiles.rb', line 46 def save_tiles @tiles = {} rows.map do |y| columns.map do |x| save_tile(x,y,Tile.new(x: x, y: y, z: @zoom)) end end end |
#stitch ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tiler/tiles.rb', line 78 def stitch output_data = Magick::ImageList.new columns.each do |column| col = Magick::ImageList.new rows.each do |row| col.push(Magick::Image.read(tile(column,row).local_file_name).first) end output_data.push(col.append(true)) end output_data.append(false).write(@output) end |
#tile(x, y) ⇒ Object
17 18 19 |
# File 'lib/tiler/tiles.rb', line 17 def tile(x,y) @tiles[y][x] end |