google-map-stitch 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +8 -0
- data/google-map-stitch.gemspec +14 -0
- data/lib/google-map-stitch.rb +4 -0
- data/lib/google-map-stitch/downloader.rb +30 -0
- data/lib/google-map-stitch/engine.rb +99 -0
- data/lib/google-map-stitch/stitcher.rb +35 -0
- data/lib/google-map-stitch/version.rb +3 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Tyler Kellen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# google-map-stitch
|
2
|
+
|
3
|
+
Download and stitch google map tiles into a single image.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
```console
|
8
|
+
gem install google-map-stitch
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Define a section of map and zoom level
|
14
|
+
```ruby
|
15
|
+
require 'google-map-stitch'
|
16
|
+
|
17
|
+
# entire map
|
18
|
+
engine = GMS::Engine.new({:zoomLevel=>2})
|
19
|
+
|
20
|
+
# subsection (South America)
|
21
|
+
engine = GMS::Engine.new({
|
22
|
+
:startX => 131,
|
23
|
+
:endX => 201,
|
24
|
+
:startY => 235,
|
25
|
+
:endY => 360,
|
26
|
+
:zoomLevel => 10
|
27
|
+
})
|
28
|
+
```
|
29
|
+
|
30
|
+
### Download Tiles
|
31
|
+
```ruby
|
32
|
+
downloader = GMS::Downloader.new(engine.tiles, 'tiles_folder')
|
33
|
+
downloader.process
|
34
|
+
```
|
35
|
+
|
36
|
+
### Combine Tiles
|
37
|
+
```ruby
|
38
|
+
stitcher = GMS::Stitcher.new('tiles_folder', 'map.png')
|
39
|
+
stitcher.process
|
40
|
+
```
|
41
|
+
|
42
|
+
> Copyright (c) 2012 Tyler Kellen. See LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../lib/google-map-stitch/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'google-map-stitch'
|
5
|
+
gem.version = GMS::VERSION
|
6
|
+
gem.summary = 'Download and stitch google map tiles into a single image.'
|
7
|
+
gem.description = gem.description
|
8
|
+
gem.author = 'Tyler Kellen'
|
9
|
+
gem.email = 'tyler@sleekcode.net'
|
10
|
+
gem.homepage = 'https://github.com/tkellen/google-map-stitch/'
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.require_paths = ['lib']
|
13
|
+
gem.add_runtime_dependency 'rmagick'
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
class GMS
|
4
|
+
class Downloader
|
5
|
+
|
6
|
+
attr_accessor :files, :output_dir
|
7
|
+
|
8
|
+
def initialize(files, output_dir="tiles")
|
9
|
+
@output_dir = output_dir
|
10
|
+
@files = files
|
11
|
+
end
|
12
|
+
|
13
|
+
def mkdir?(dir)
|
14
|
+
Dir.mkdir(dir) if !Dir.exists?(dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
def process
|
18
|
+
mkdir?(@output_dir)
|
19
|
+
@files.each do |tile|
|
20
|
+
mkdir?(File.join(@output_dir,tile[:dir]))
|
21
|
+
File.open(File.join(@output_dir,tile[:dir],tile[:file]), 'w+') do |file|
|
22
|
+
open(tile[:url], 'rb') do |image|
|
23
|
+
file.write(image.read)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class GMS
|
2
|
+
class Engine
|
3
|
+
|
4
|
+
attr_accessor :startX, :endX, :startY, :endY, :zoomLevel, :layer
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
|
8
|
+
@zoomLevel = config[:zoomLevel]||2
|
9
|
+
|
10
|
+
# two is the minimum zoom level
|
11
|
+
@zoomLevel = 2 if config[:zoomLevel] < 2
|
12
|
+
|
13
|
+
# if all starting and ending coords are not defined, then
|
14
|
+
# assume we want the whole map
|
15
|
+
if ![:startX,:endX,:startY,:endY].all? { |key| config.has_key?(key) }
|
16
|
+
@startX = 0
|
17
|
+
@endX = 2**config[:zoomLevel]-1
|
18
|
+
@startY = 0
|
19
|
+
@endY = 2**config[:zoomLevel]-1
|
20
|
+
else
|
21
|
+
@startX = config[:startX]
|
22
|
+
@endX = config[:endX]
|
23
|
+
@startY = config[:startY]
|
24
|
+
@endY = config[:endY]
|
25
|
+
end
|
26
|
+
|
27
|
+
# allow the downloaded layer to be customized
|
28
|
+
@layer = config[:layerID] || "m@195000000"
|
29
|
+
|
30
|
+
status
|
31
|
+
end
|
32
|
+
|
33
|
+
# total width in tiles
|
34
|
+
def width
|
35
|
+
@endX-@startX
|
36
|
+
end
|
37
|
+
|
38
|
+
# total height in tiles
|
39
|
+
def height
|
40
|
+
@endY-@startY
|
41
|
+
end
|
42
|
+
|
43
|
+
# total width in pixels
|
44
|
+
def pixelWidth
|
45
|
+
width*256
|
46
|
+
end
|
47
|
+
|
48
|
+
# total height in pixels
|
49
|
+
def pixelHeight
|
50
|
+
width*256
|
51
|
+
end
|
52
|
+
|
53
|
+
# total width printed @ 300 dpi (in inches)
|
54
|
+
def printWidth(dpi=300)
|
55
|
+
(pixelWidth.to_f/dpi).round(2)
|
56
|
+
end
|
57
|
+
|
58
|
+
# total height printed @ 300 dpi (in inches)
|
59
|
+
def printHeight(dpi=300)
|
60
|
+
(pixelHeight.to_f/dpi).round(2)
|
61
|
+
end
|
62
|
+
|
63
|
+
# total number of tiles to download
|
64
|
+
def tileCount
|
65
|
+
width*height
|
66
|
+
end
|
67
|
+
|
68
|
+
# build a url for a google image
|
69
|
+
def imageURL(x, y, z, layer=@layer)
|
70
|
+
"http://mt1.google.com/vt/lyrs=#{layer}&hl=en&x=#{x}&s=&y=#{y}&z=#{z.to_s}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def status
|
74
|
+
puts "\Google Map Stitch Configuration"
|
75
|
+
puts "======================================================="
|
76
|
+
puts "Starting Coord: #{@startX},#{@endX}"
|
77
|
+
puts "Ending Coord: #{@startY},#{@endY}"
|
78
|
+
puts "Zoom Level: #{@zoomLevel}"
|
79
|
+
puts "Total Tiles to Download: #{tileCount.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse}"
|
80
|
+
puts "Final Image Size @ 72DPI #{pixelWidth}x#{pixelHeight}"
|
81
|
+
puts "Final Print Size @ 300DPI (Inches): #{printWidth}\"x#{printHeight}\""
|
82
|
+
puts "Final Print Size @ 300DPI (Feet): #{(printWidth/12).round(2)}'x#{(printHeight/12).round(2)}'"
|
83
|
+
puts "=======================================================\n\n"
|
84
|
+
end
|
85
|
+
|
86
|
+
# list all tiles
|
87
|
+
def tiles
|
88
|
+
@startY.upto(@endY).map.with_index do |x, c|
|
89
|
+
@startX.upto(@endX).map.with_index do |y, r|
|
90
|
+
{
|
91
|
+
:url => imageURL(x,y,@zoomLevel,@layer),
|
92
|
+
:dir => "r#{"%06d" % r}",
|
93
|
+
:file => "c#{"%06d" % c}.png"
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end.flatten
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
3
|
+
class GMS
|
4
|
+
class Stitcher
|
5
|
+
|
6
|
+
attr_accessor :dir, :output_file
|
7
|
+
|
8
|
+
def initialize(dir, output_file="map.png")
|
9
|
+
@dir = dir
|
10
|
+
@output_file = output_file
|
11
|
+
end
|
12
|
+
|
13
|
+
def tiles
|
14
|
+
Dir.glob(File.join(dir,"*")).map do |path|
|
15
|
+
Dir.glob(File.join(path,"*.png")).map do |image|
|
16
|
+
image
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
output = Magick::ImageList.new
|
23
|
+
|
24
|
+
tiles.each do |row|
|
25
|
+
column = Magick::ImageList.new
|
26
|
+
row.each do |file|
|
27
|
+
puts "Combining #{file}"
|
28
|
+
column.push(Magick::Image.read(file).first)
|
29
|
+
end
|
30
|
+
output.push(column.append(false))
|
31
|
+
end
|
32
|
+
output.append(true).write(@output_file)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-map-stitch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tyler Kellen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rmagick
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ''
|
31
|
+
email: tyler@sleekcode.net
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- google-map-stitch.gemspec
|
42
|
+
- lib/google-map-stitch.rb
|
43
|
+
- lib/google-map-stitch/downloader.rb
|
44
|
+
- lib/google-map-stitch/engine.rb
|
45
|
+
- lib/google-map-stitch/stitcher.rb
|
46
|
+
- lib/google-map-stitch/version.rb
|
47
|
+
homepage: https://github.com/tkellen/google-map-stitch/
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Download and stitch google map tiles into a single image.
|
71
|
+
test_files: []
|
72
|
+
has_rdoc:
|