mapsnatcher 0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -0
  3. data/VERSION +1 -1
  4. data/bin/mapsnatcher +25 -10
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81899844de71e7d8e994867d291b9bf3effee5eac3af6a07686c9b9ee201660d
4
- data.tar.gz: 98a6fc9902a46b0a8afc38df9471c805a0a0555066cb516d357a1ad68da76db2
3
+ metadata.gz: 15abc2e7d72ccee7fbc1d86065724bde5ac5eac4bd3312638e4dade03ea4bed2
4
+ data.tar.gz: 9aaa5ef18519acaeae3c08f1149cab60ea39a86258b1307b2b5f3d109a191200
5
5
  SHA512:
6
- metadata.gz: de0a27be646d2d197f4342c8525a5e5625074eb2d6e47c412e7d9e46dbfc50e795d877b2b621148658784caa60a47c76929cbcc9f4d4442029376ba85818f143
7
- data.tar.gz: b72ac47c23bd90ffeb8744af6ba569142e85a967dd55822bc07cc1130815be07894fce94b94f24aa65fbf0d8d32a3e554adbf3975c20946154c139528a033b9e
6
+ metadata.gz: 54d9e64a64d4fbcd84e30cad8ebcb379fe93cc8062e02f2fb030f377c8f617bead2a5c781b49f3fe4cd8bd9287c872ecb30605099ab5e92abab01a0d1fa64176
7
+ data.tar.gz: ca3d48e227460f0cbd8628f4b0a2f24268313dd2508452a4e0d266c2a4e0d937da22c069eee9da1f0c7f56b5302cc477d93c9db13de147501a4001d92c8f2090
data/README.md CHANGED
@@ -9,6 +9,20 @@ You can use a tool such as
9
9
  [ChromeCacheView](https://www.nirsoft.net/utils/chrome_cache_view.html) to find
10
10
  these URLs easily.
11
11
 
12
+ ## Installation
13
+
14
+ You will need ImageMagick and its development headers installed in order to
15
+ build the dependencies. For Ubuntu these are:
16
+
17
+ ```sudo apt-get install imagemagick libmagickwand-dev```
18
+
19
+ Once set up, install through RubyGems:
20
+
21
+ ```gem install mapsnatcher```
22
+
23
+ To process larger maps, you may need to comment out or modify the resource
24
+ policies in `/etc/ImageMagick-6/policy.xml`.
25
+
12
26
  ## Usage
13
27
 
14
28
  Usage is as follows:
@@ -24,3 +38,5 @@ boundaries that you would like to capture.
24
38
  If you are unsure of the boundaries and would like to capture the entire map,
25
39
  add the `-b` argument and you will only need to enter one valid coordinate;
26
40
  `mapsnatcher` will do the rest.
41
+
42
+ If you would like to save the tiles, add the `-s` argument.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.1.2
data/bin/mapsnatcher CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "fileutils"
4
- require "yaml"
5
4
  require "open-uri"
6
5
  require "net/http"
7
6
  require "rmagick"
8
7
  include Magick
9
8
 
10
9
  TEMP_DIR = "./.ms.tmp"
10
+ TILES_DIR = "./tiles"
11
11
 
12
12
  # False if URL returns a 200
13
13
  #
@@ -34,6 +34,7 @@ if ARGV.empty? or %w[-h --help].include? ARGV.first
34
34
  puts " in the URL. The first number is typically the zoom level, which is constant."
35
35
  puts
36
36
  puts " [-b] find outer bounds of map automatically"
37
+ puts " [-s] save tiles to a directory ./tiles/"
37
38
  exit 0
38
39
  end
39
40
 
@@ -51,10 +52,16 @@ elsif !Dir.empty? TEMP_DIR
51
52
  puts
52
53
  end
53
54
 
54
- if ARGV.include? "-b"
55
+ save_tiles = false
56
+ if (args = ARGV).include? "-s"
57
+ args -= ["-s"]
58
+ save_tiles = true
59
+ end
60
+
61
+ if args.include? "-b"
55
62
  # Automatic boundary mode
56
63
 
57
- url = (ARGV - ["-b"]).first
64
+ url = (args - ["-b"]).first
58
65
 
59
66
  # CLI input function
60
67
  #
@@ -104,7 +111,7 @@ if ARGV.include? "-b"
104
111
  else
105
112
  # User input coordinate mode
106
113
 
107
- url = ARGV.first
114
+ url = args.first
108
115
 
109
116
  # CLI input function
110
117
  #
@@ -141,7 +148,8 @@ end
141
148
  # Use the tile at 0, 0 to calculate final image size
142
149
  sample = Image.from_blob(URI.open(build_url url, x_range.first, y_range.first).read).first
143
150
  final_size = {x: sample.columns * x_range.size, y: sample.rows * y_range.size}
144
- puts "Image found, #{sample.format} size #{final_size[:x]}x#{final_size[:y]}"
151
+ format = sample.format
152
+ puts "Image found, #{format} size #{final_size[:x]}x#{final_size[:y]}"
145
153
  puts
146
154
 
147
155
  dl_counter = 0
@@ -153,16 +161,17 @@ y_range.each do |y|
153
161
  x_range.each do |x|
154
162
  print "Downloading... [#{dl_counter += 1}/#{dl_total}]\r"
155
163
 
156
- temp = "#{TEMP_DIR}/#{x}_#{y}.tmp"
164
+ temp = "#{TEMP_DIR}/#{x}_#{y}.#{format.downcase}"
157
165
  if File.exists? temp
158
166
  # Load the backup file
159
- blob = YAML.load(File.read temp)
167
+ img = Image.read(temp).first
160
168
  else
161
169
  blob = URI.open(build_url url, x, y).read
162
- File.open(temp, "w") { |f| f.write(YAML.dump blob) }
170
+ File.open(temp, "wb") { |f| f.write blob }
171
+ img = Image.from_blob(blob).first
163
172
  end
164
173
 
165
- row.push Image.from_blob(blob).first
174
+ row.push img
166
175
  end
167
176
 
168
177
  stitch.push row.append(false)
@@ -188,5 +197,11 @@ print "Enter file name for map: "
188
197
  filename = STDIN.gets.chomp
189
198
  print "Saving, this may take a minute..."
190
199
  stitch.append(true).write filename
191
- FileUtils.rm_rf TEMP_DIR
192
200
  puts "\nImage written to: #{filename}"
201
+
202
+ if save_tiles
203
+ File.rename TEMP_DIR, TILES_DIR
204
+ puts "Tiles saved to: #{TILES_DIR.match /\w+/}/"
205
+ else
206
+ FileUtils.rm_rf TEMP_DIR
207
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapsnatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-11-28 00:00:00.000000000 Z
@@ -40,7 +40,7 @@ homepage: https://github.com/vinnydiehl/mapsnatcher
40
40
  licenses:
41
41
  - MIT
42
42
  metadata: {}
43
- post_install_message:
43
+ post_install_message:
44
44
  rdoc_options: []
45
45
  require_paths:
46
46
  - lib
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubygems_version: 3.3.5
59
- signing_key:
59
+ signing_key:
60
60
  specification_version: 4
61
61
  summary: Downloads and combines tiles from QGIS maps into an image.
62
62
  test_files: []