osm-rb 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6914beed298de2adfe541882f7af0900238ac71a2526cd2b8cf02af79714d6c
4
- data.tar.gz: fbaafa9dd9b5fd9e0eef6d94366a99eb2503151446980320169f525a98b3c9fd
3
+ metadata.gz: c8722157dc3164423554472b22d437edefd72ceceddad8a2d358d99bc1efba21
4
+ data.tar.gz: 322213744de09a80b61cc169a9c9ed9538649c33bedfb7fe2ceaaa2667b3b504
5
5
  SHA512:
6
- metadata.gz: 2884743ee6007b59692099b36073f5b538fa0cfb9aedc65b797988f1447f59c4064d0efcfb5b323fa7f487c54322440acfcdacd8bf13b31b2ae32d7021fa702c
7
- data.tar.gz: 716bda4e07b52e699fae7409111a321fb900520deb591d0b4d7464d3b27632739bd312d2d88e79de8c3cead7376ccac18c5cb232f2a4ae6157abe8c5cab95d99
6
+ metadata.gz: fea9622e74c5d7cefc294bb7e531d54185148e7d4c9b9a0729c81cea98762976e7ed3c0eb09e5291c3a4f2baaf227380f3f38b82615f6a302fbad81e015ae2d9
7
+ data.tar.gz: 893e4ecc0a9170173721a5b7de08bba6dbeee53276cb1e8054bf0a197952c074f292152923ef5ffb07f0a07840c6b71738f3106e72e59591ca22cd88fb1c5926
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile.lock CHANGED
@@ -2,11 +2,15 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  osm-rb (0.0.1)
5
+ typhoeus (~> 1.3.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.3)
11
+ ethon (0.12.0)
12
+ ffi (>= 1.3.0)
13
+ ffi (1.12.2)
10
14
  rake (10.5.0)
11
15
  rspec (3.9.0)
12
16
  rspec-core (~> 3.9.0)
@@ -21,6 +25,8 @@ GEM
21
25
  diff-lcs (>= 1.2.0, < 2.0)
22
26
  rspec-support (~> 3.9.0)
23
27
  rspec-support (3.9.2)
28
+ typhoeus (1.3.1)
29
+ ethon (>= 0.9.0)
24
30
 
25
31
  PLATFORMS
26
32
  ruby
data/README.md CHANGED
@@ -61,6 +61,48 @@ dimensions.x # => 12
61
61
  dimensions.y # => 8
62
62
  ```
63
63
 
64
+ ### Exporter
65
+
66
+ The exporter allows you to donwload and store tile images. It is also able to automatically stitch
67
+ them together.
68
+
69
+ To create an exporter, you have to pass it an array of tile server url templates and a zoom level
70
+
71
+ ```ruby
72
+ urls = [
73
+ 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png',
74
+ 'https://b.tile.opentopomap.org/{z}/{x}/{y}.png',
75
+ 'https://c.tile.opentopomap.org/{z}/{x}/{y}.png'
76
+ ]
77
+ zoom_level = 13
78
+ exporter = OSM::Exporter.new(urls, zoom_level)
79
+ ```
80
+
81
+ Download the specified tiles
82
+
83
+ ```ruby
84
+ tiles = [
85
+ OpenStruct.new(lat: 46.95127, lng: 7.43878),
86
+ OpenStruct.new(lat: 46.92771, lng: 7.44610),
87
+ OpenStruct.new(lat: 46.94764, lng: 7.37527)
88
+ ]
89
+ images = exporter.download_tiles_as_blob(tiles)
90
+ # images is an array of the binary data of the tiles
91
+ ```
92
+
93
+ You can use any of the compatible [caches for Typhoeus](https://github.com/typhoeus/typhoeus#caching)
94
+ and follow their instructions.
95
+
96
+ To use a Redis cache
97
+
98
+ ```ruby
99
+ require 'redis'
100
+ redis = Redis.new(...)
101
+ Typhoeus::Config.cache = Typhoeus::Cache::Redis.new(redis)
102
+ ```
103
+
104
+
105
+
64
106
  ## Development
65
107
 
66
108
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,9 +1,8 @@
1
1
  require 'ostruct'
2
2
 
3
3
  module OSM
4
- TILE_SIZE = 256
5
-
6
4
  class Calculator
5
+ TILE_SIZE = 256
7
6
  attr_reader :zoom, :padding, :target_size
8
7
 
9
8
  def initialize(zoom, padding, target_size)
@@ -17,7 +16,6 @@ module OSM
17
16
  d = Calculator.new(level, padding, target_size)
18
17
  path_size = d.path_pixel_dimensions(path)
19
18
  if path_size.x + padding.x <= target_size.x && path_size.y + padding.y <= target_size.y
20
- # puts "Fit #{path_size} into #{target_size} at zoom level #{level}"
21
19
  return level
22
20
  end
23
21
  end
@@ -0,0 +1,29 @@
1
+ require 'typhoeus'
2
+
3
+ module OSM
4
+ class Exporter
5
+ TILE_SIZE = 256
6
+ attr_reader :tile_urls, :zoom
7
+
8
+ def initialize(tile_urls, zoom)
9
+ @tile_urls = Array(tile_urls)
10
+ @zoom = zoom
11
+ end
12
+
13
+ def download_tiles_as_blob(tiles)
14
+ url = tile_urls.sample()
15
+ hydra = Typhoeus::Hydra.new
16
+ requests = tiles.map do |tile|
17
+ tile_url = url.gsub('{x}', tile.x.to_s).gsub('{y}', tile.y.to_s).gsub('{z}', zoom.to_s)
18
+ request = Typhoeus::Request.new(tile_url)
19
+ hydra.queue(request)
20
+ request
21
+ end
22
+ hydra.run
23
+
24
+ requests.map do |request|
25
+ request.response.body
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/osm.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module OSM
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
 
4
4
  require_relative 'osm/calculator'
5
+ require_relative 'osm/exporter'
5
6
  end
data/osm-rb.gemspec CHANGED
@@ -33,4 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "bundler", "~> 2.0"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_dependency "typhoeus", "~> 1.3.1"
36
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osm-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas_Skywalker
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.1
55
69
  description: '["OSM-rb", "allows", "you", "to", "manipulate", "and", "export", "OSM",
56
70
  "map", "tiles.", "This", "includes", "downloading", "tiles,cropping", "to", "any",
57
71
  "specified", "region,", "drawing", "routes", "on", "the", "map", "and", "exporting",
@@ -62,6 +76,7 @@ executables: []
62
76
  extensions: []
63
77
  extra_rdoc_files: []
64
78
  files:
79
+ - ".gitignore"
65
80
  - CHANGELOG.md
66
81
  - CODE_OF_CONDUCT.md
67
82
  - Gemfile
@@ -73,6 +88,7 @@ files:
73
88
  - bin/setup
74
89
  - lib/osm.rb
75
90
  - lib/osm/calculator.rb
91
+ - lib/osm/exporter.rb
76
92
  - osm-rb.gemspec
77
93
  homepage: https://github.com/code-fabrik/osm-rb
78
94
  licenses: