osm_tile_grabber 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd3ae72fc77a01e685e0b96d9e6ca458ab013209
4
+ data.tar.gz: 9b42bf56b6bf72a9222dbf7b39b9eb6ebecf1569
5
+ SHA512:
6
+ metadata.gz: d611b13ab9bab88270daecbdd6fc3681f1d02b9581e376f67c30b6df8995964cb7c817789c6dd486a72ffe1527a234d5f4397162e688986873ff8d5ba1d28edd
7
+ data.tar.gz: e16086a5393ed52d5310399a5a1c576b71a389a9422d639dccc5f65aea92ed6f9810d6107020cf97a1ae341a3b3502b121e92704f7a56f43db83371999169b9a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in osm_tile_grabber.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Luke Picciau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # OSM Tile Grabber
2
+ A simple gem for getting an image of a desired location using OSM tiles. This is fairly beta
3
+ software and will likely change soon to make it nicer to use.
4
+
5
+ # Usage
6
+
7
+ **Note:** You need to have rmagick installed for this gem to work. I will work on making this easier but for now just follow the instructions on the readme https://github.com/rmagick/rmagick
8
+
9
+
10
+ ## Usage warning:
11
+ Downloading large amounts of data from the openstreetmap.org tileserver is strictly forbidden. This gem is **NOT** to be used for downloading large maps from OSM for offline use.
12
+ If you need local copies of large amounts of OSM tiles you must set up your own tile server or find a new tileserver where this is permitted.
13
+ More info can be found at: https://operations.osmfoundation.org/policies/tiles/
14
+
15
+ ---
16
+
17
+ Create an instance of OSMTileGrabber
18
+
19
+ `OSMTileGrabber.new(lat1, lon1, lat2, lon2, zoom)`
20
+
21
+ lat1 and lon1 are the coordinates of the top left corner of the map you wish to download. lat2 and
22
+ lon2 is the bottom right coordinate. Zoom is the zoom level you wish to download the map at (1-19)
23
+ a higher zoom will create a bigger image with more detail.
24
+
25
+ to download the image run `create_image("<output_path>")` on the object instance. This will save the
26
+ final image at the path provided.
27
+
28
+ ## Example
29
+
30
+ ```
31
+ require 'osm_tile_grabber'
32
+ osm = OSMTileGrabber.new(-34.9220585,138.5879188,-34.9397,138.6239,15)
33
+ osm.create_image("/tmp/output.png")
34
+ ```
35
+
36
+ ![example output map](https://i.imgur.com/Fjmglog.png)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "osm_tile_grabber"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "osm_tile_grabber/version"
2
+ require "osm_tile_grabber/osm_tile_grabber"
@@ -0,0 +1,81 @@
1
+ require 'open-uri'
2
+ require 'tempfile'
3
+ require 'rmagick'
4
+ include Magick
5
+
6
+ class OSMTileGrabber
7
+ def initialize(lat1, lon1, lat2, lon2, zoom)
8
+ @lat1 = lat1
9
+ @lon1 = lon1
10
+ @lat2 = lat2
11
+ @lon2 = lon2
12
+ @zoom = zoom
13
+ end
14
+
15
+ def create_image(output_path)
16
+ self.montage(self.download_tiles, output_path)
17
+ end
18
+
19
+ def tile_numbers_needed
20
+ top_left_tile = get_tile_number(@lat1, @lon1)
21
+ bottom_right_tile = get_tile_number(@lat2, @lon2)
22
+ tile_matrix = []
23
+
24
+ (top_left_tile[:y]..bottom_right_tile[:y]).each do |y|
25
+ row = []
26
+ (top_left_tile[:x]..bottom_right_tile[:x]).each do |x|
27
+ row << {x: x, y: y}
28
+ end
29
+ tile_matrix << row
30
+ end
31
+ return tile_matrix
32
+ end
33
+
34
+ def image_dimentions
35
+ top_left_tile = get_tile_number(@lat1, @lon1)
36
+ bottom_right_tile = get_tile_number(@lat2, @lon2)
37
+
38
+ x = bottom_right_tile[:x] - top_left_tile[:x]
39
+ y = bottom_right_tile[:y] - top_left_tile[:y]
40
+ return {x: x + 1, y: y + 1}
41
+ end
42
+
43
+ def get_tile_number(lat_deg, lng_deg)
44
+ lat_rad = lat_deg/180 * Math::PI
45
+ n = 2.0 ** @zoom
46
+ x = ((lng_deg + 180.0) / 360.0 * n).to_i
47
+ y = ((1.0 - Math::log(Math::tan(lat_rad) + (1 / Math::cos(lat_rad))) / Math::PI) / 2.0 * n).to_i
48
+
49
+ {:x => x, :y =>y}
50
+ end
51
+
52
+ def link_from_tile_number(x,y)
53
+ # TODO: Allow picking own tileserver
54
+ "https://a.tile.openstreetmap.org/#{@zoom}/#{x}/#{y}.png"
55
+ end
56
+
57
+ def download_tiles
58
+ tile_files = []
59
+ tile_numbers_needed.each do |row|
60
+ row.each do |tn|
61
+ tile_file = Tempfile.new(["tile-#{@zoom}-#{tn[:x]}-#{tn[:y]}", ".png"])
62
+ link_from_tile_number(tn[:x], tn[:y])
63
+ open(link_from_tile_number(tn[:x], tn[:y]), "rb") do |read_file|
64
+ tile_file.write(read_file.read)
65
+ end
66
+ tile_files << tile_file.path
67
+ end
68
+ end
69
+ return tile_files
70
+ end
71
+
72
+ def montage(file_paths, output_path)
73
+ image_list = ImageList.new *file_paths
74
+ tile_string = "#{image_dimentions[:x]}x#{image_dimentions[:y]}"
75
+ tiled_montage = image_list.montage do
76
+ self.geometry = "+0+0"
77
+ self.tile = tile_string
78
+ end
79
+ tiled_montage.write(output_path)
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module OsmTileGrabber
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "osm_tile_grabber/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "osm_tile_grabber"
8
+ spec.version = OsmTileGrabber::VERSION
9
+ spec.authors = ["Luke Picciau"]
10
+ spec.email = ["luke.b.picciau@gmail.com"]
11
+
12
+ spec.summary = "Gem for creating an image from OSM of an area"
13
+ spec.description = "Gem for creating an image from OSM of an area"
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+
28
+ spec.add_dependency "rmagick"
29
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osm_tile_grabber
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Picciau
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rmagick
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem for creating an image from OSM of an area
70
+ email:
71
+ - luke.b.picciau@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/osm_tile_grabber.rb
84
+ - lib/osm_tile_grabber/osm_tile_grabber.rb
85
+ - lib/osm_tile_grabber/version.rb
86
+ - osm_tile_grabber.gemspec
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.14
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Gem for creating an image from OSM of an area
111
+ test_files: []