class TilesCollection
Attributes
dir[RW]
end[R]
output_file[RW]
source[RW]
start[R]
zoom[RW]
Public Class Methods
new(args)
click to toggle source
# 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
Public Instance Methods
all()
click to toggle source
# File lib/tiler/tiles.rb, line 29 def all @tiles end
cleanup()
click to toggle source
# 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()
click to toggle source
# File lib/tiler/tiles.rb, line 25 def columns @start_x.upto(@end_x) end
create_temp_dir()
click to toggle source
# File lib/tiler/tiles.rb, line 56 def create_temp_dir @dir = Dir.mktmpdir end
delete_temp_dir()
click to toggle source
# File lib/tiler/tiles.rb, line 61 def delete_temp_dir FileUtils.remove_entry_secure dir if dir end
download()
click to toggle source
# File lib/tiler/tiles.rb, line 65 def download create_temp_dir flatten.each{ |tile| tile.download(dir) } end
flatten()
click to toggle source
# 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()
click to toggle source
# File lib/tiler/tiles.rb, line 21 def rows @start_y.upto(@end_y) end
save_tile(x,y,tile)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/tiler/tiles.rb, line 17 def tile(x,y) @tiles[y][x] end