Class: TilesCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/tiler/tiles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#endObject (readonly)

Returns the value of attribute end.



4
5
6
# File 'lib/tiler/tiles.rb', line 4

def end
  @end
end

#output_fileObject

Returns the value of attribute output_file.



3
4
5
# File 'lib/tiler/tiles.rb', line 3

def output_file
  @output_file
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/tiler/tiles.rb', line 3

def source
  @source
end

#startObject (readonly)

Returns the value of attribute start.



4
5
6
# File 'lib/tiler/tiles.rb', line 4

def start
  @start
end

#zoomObject

Returns the value of attribute zoom.



3
4
5
# File 'lib/tiler/tiles.rb', line 3

def zoom
  @zoom
end

Instance Method Details

#allObject



29
30
31
# File 'lib/tiler/tiles.rb', line 29

def all
  @tiles
end

#cleanupObject



59
60
61
62
63
64
# File 'lib/tiler/tiles.rb', line 59

def cleanup
  flatten.each do |tile| 
    tile.file.close
    tile.file.unlink
  end
end

#columnsObject



25
26
27
# File 'lib/tiler/tiles.rb', line 25

def columns
  @start_x.upto(@end_x)
end

#downloadObject



55
56
57
# File 'lib/tiler/tiles.rb', line 55

def download
  flatten.each{ |tile| tile.download }
end

#flattenObject



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

#rowsObject



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_tilesObject



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

#stitchObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tiler/tiles.rb', line 66

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