global_map_tiles 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 +7 -0
- data/.github/issue_template.md +17 -0
- data/.github/pull_request_template.md +7 -0
- data/.github/workflows/ci.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/global_map_tiles.gemspec +24 -0
- data/lib/global_map_tiles.rb +3 -0
- data/lib/global_map_tiles/global_geodetic.rb +39 -0
- data/lib/global_map_tiles/global_mercator.rb +114 -0
- data/lib/global_map_tiles/version.rb +3 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a56cacdab24343623ecc353a44b467f0ee1031c8f8be248ccf0345478dc94332
|
4
|
+
data.tar.gz: 8310d29ae51036ae6da881a0b6307ca84c545f9e5e469c69a8e8892355d2854a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ca773532591da76a8408fa9cabb4a70d0d061fa81618ee49e521ea15d644bd0bb03ed5b57fe797a5b2ac4659e7d31e1c197af4769e3b30b774d804654fc9b16
|
7
|
+
data.tar.gz: 1e7eae834a0f5c6f09fc0623e6a0e61b2af4955496c1ad20a83ef12526f7dc58d20d2c8ce042c8a771fcb67bb61f582829353679380c87d25c45a8e10be8952e
|
@@ -0,0 +1,17 @@
|
|
1
|
+
## Expected behavior
|
2
|
+
|
3
|
+
Describe here how you expected the gem to behave in this particular situation.
|
4
|
+
|
5
|
+
## Actual behavior
|
6
|
+
|
7
|
+
Describe here what actually happened.
|
8
|
+
|
9
|
+
## Steps to reproduce the problem
|
10
|
+
|
11
|
+
This is extremely important! Providing us with a reliable way to reproduce
|
12
|
+
a problem will expedite its solution.
|
13
|
+
|
14
|
+
## Specifications
|
15
|
+
|
16
|
+
- Version:
|
17
|
+
- Platform:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
os: [ubuntu, macos]
|
9
|
+
ruby: [2.5, 2.6, 2.7, head, jruby]
|
10
|
+
runs-on: ${{ matrix.os }}-latest
|
11
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- run: bundle install
|
18
|
+
- run: bundle exec rake default
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
global_map_tiles (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
parallel (1.19.1)
|
12
|
+
parser (2.7.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.1)
|
16
|
+
regexp_parser (1.8.2)
|
17
|
+
rexml (3.2.4)
|
18
|
+
rspec (3.9.0)
|
19
|
+
rspec-core (~> 3.9.0)
|
20
|
+
rspec-expectations (~> 3.9.0)
|
21
|
+
rspec-mocks (~> 3.9.0)
|
22
|
+
rspec-core (3.9.1)
|
23
|
+
rspec-support (~> 3.9.1)
|
24
|
+
rspec-expectations (3.9.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-mocks (3.9.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-support (3.9.2)
|
31
|
+
rubocop (1.2.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.7.1.5)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.0.1)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
40
|
+
rubocop-ast (1.1.1)
|
41
|
+
parser (>= 2.7.1.5)
|
42
|
+
rubocop-performance (1.8.1)
|
43
|
+
rubocop (>= 0.87.0)
|
44
|
+
rubocop-ast (>= 0.4.0)
|
45
|
+
ruby-progressbar (1.10.1)
|
46
|
+
standard (0.9.0)
|
47
|
+
rubocop (= 1.2.0)
|
48
|
+
rubocop-performance (= 1.8.1)
|
49
|
+
unicode-display_width (1.6.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
global_map_tiles!
|
56
|
+
rake (~> 13.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
standard
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Xavier Delamotte
|
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,50 @@
|
|
1
|
+
# GlobalMapTiles
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
Ruby port of the script "Tiles à la Google Maps: Coordinates, Tile Bounds and Projection" from http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
|
6
|
+
|
7
|
+
Lon/Lat convention was chosen over Lat/Lon as it's the convention of [GeoJSON](https://geojson.org/).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "global_map_tiles"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install global_map_tiles
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
|
29
|
+
require "global_map_tiles"
|
30
|
+
|
31
|
+
mercator = GlobalMapTiles::GlobalMercator.new
|
32
|
+
puts mercator.lon_lat_to_meters(13.24, 52.31)
|
33
|
+
puts mercator.meters_to_lon_lat(1473870.058102942, 6856372.69101939)
|
34
|
+
```
|
35
|
+
|
36
|
+
See all the examples in [spec/global_mercator_spec.rb](spec/global_mercator_spec.rb)
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/x4d3/global_map_tiles.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "global_map_tiles"
|
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,24 @@
|
|
1
|
+
require_relative "lib/global_map_tiles/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "global_map_tiles"
|
5
|
+
spec.version = GlobalMapTiles::VERSION
|
6
|
+
spec.authors = ["Xavier Delamotte"]
|
7
|
+
spec.email = ["git@xade.eu"]
|
8
|
+
|
9
|
+
spec.summary = "Ruby port of globalmaptiles.py"
|
10
|
+
spec.description = 'Ruby port of the script "Tiles à la Google Maps: Coordinates, Tile Bounds and Projection" from http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/'
|
11
|
+
spec.homepage = "https://github.com/x4d3/global_map_tiles"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/x4d3/global_map_tiles"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module GlobalMapTiles
|
2
|
+
# Functions necessary for generation of global tiles in Plate Carre projection, EPSG:4326, "unprojected profile".
|
3
|
+
class GlobalGeodetic
|
4
|
+
def initialize(tile_size = 256)
|
5
|
+
@tile_size = tile_size
|
6
|
+
end
|
7
|
+
|
8
|
+
# Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid
|
9
|
+
def lon_lat_to_pixels(lon, lat, zoom)
|
10
|
+
res = 180 / 256.0 / 2**zoom
|
11
|
+
px = (180 + lat) / res
|
12
|
+
py = (90 + lon) / res
|
13
|
+
[px, py]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns coordinates of the tile covering region in pixel coordinates
|
17
|
+
def pixels_to_tile(px, py)
|
18
|
+
tx = ((px / @tile_size.to_f).ceil - 1).to_i
|
19
|
+
ty = ((py / @tile_size.to_f).ceil - 1).to_i
|
20
|
+
[tx, ty]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Resolution (arc/pixel) for given zoom level (measured at Equator)"
|
24
|
+
def resolution(zoom)
|
25
|
+
(180 / 256.0) / 2**zoom
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns bounds of the given tile
|
29
|
+
def tile_bounds(tx, ty, zoom)
|
30
|
+
res = 180 / 256.0 / 2**zoom
|
31
|
+
[
|
32
|
+
tx * 256 * res - 180,
|
33
|
+
ty * 256 * res - 90,
|
34
|
+
(tx + 1) * 256 * res - 180,
|
35
|
+
(ty + 1) * 256 * res - 90
|
36
|
+
]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module GlobalMapTiles
|
2
|
+
# based on EPSG:900913 = EPSG:3785
|
3
|
+
class GlobalMercator
|
4
|
+
def initialize(tile_size = 256)
|
5
|
+
@tile_size = tile_size
|
6
|
+
@initial_resolution = 2 * Math::PI * 6378137 / @tile_size
|
7
|
+
@origin_shift = 2 * Math::PI * 6378137 / 2.0
|
8
|
+
end
|
9
|
+
|
10
|
+
# Converts given lon/lat in WGS84 Datum to XY in Spherical Mercator EPSG:900913
|
11
|
+
def lon_lat_to_meters(lon, lat)
|
12
|
+
mx = lon * @origin_shift / 180.0
|
13
|
+
my = Math.log(Math.tan((90 + lat) * Math::PI / 360.0)) / (Math::PI / 180.0)
|
14
|
+
|
15
|
+
my = my * @origin_shift / 180.0
|
16
|
+
[mx, my]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Converts XY point from Spherical Mercator EPSG:900913 to lon/lat in WGS84 Datum"
|
20
|
+
def meters_to_lon_lat(mx, my)
|
21
|
+
lon = (mx / @origin_shift) * 180.0
|
22
|
+
lat = (my / @origin_shift) * 180.0
|
23
|
+
|
24
|
+
lat = 180 / Math::PI * (2 * Math.atan(Math.exp(lat * Math::PI / 180.0)) - Math::PI / 2.0)
|
25
|
+
[lon, lat]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
|
29
|
+
def pixels_to_meters(px, py, zoom)
|
30
|
+
res = resolution(zoom)
|
31
|
+
mx = px * res - @origin_shift
|
32
|
+
my = py * res - @origin_shift
|
33
|
+
[mx, my]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
|
37
|
+
def meters_to_pixels(mx, my, zoom)
|
38
|
+
res = resolution(zoom)
|
39
|
+
px = (mx + @origin_shift) / res
|
40
|
+
py = (my + @origin_shift) / res
|
41
|
+
[px, py]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a tile covering region in given pixel coordinates
|
45
|
+
def pixels_to_tile(px, py)
|
46
|
+
tx = (px / @tile_size.to_f).ceil.to_i - 1
|
47
|
+
ty = (py / @tile_size.to_f).ceil.to_i - 1
|
48
|
+
[tx, ty]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Move the origin of pixel coordinates to top-left corner
|
52
|
+
def pixels_to_raster(px, py, zoom)
|
53
|
+
map_size = @tile_size << zoom
|
54
|
+
[px, map_size - py]
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns tile for given mercator coordinates
|
58
|
+
def meters_to_tile(mx, my, zoom)
|
59
|
+
px, py = meters_to_pixels(mx, my, zoom)
|
60
|
+
pixels_to_tile(px, py)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns bounds of the given tile in EPSG:900913 coordinates
|
64
|
+
def tile_bounds(tx, ty, zoom)
|
65
|
+
min_x, min_y = pixels_to_meters(tx * @tile_size, ty * @tile_size, zoom)
|
66
|
+
max_x, max_y = pixels_to_meters((tx + 1) * @tile_size, (ty + 1) * @tile_size, zoom)
|
67
|
+
[min_x, min_y, max_x, max_y]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns bounds of the given tile in longitude/latitude using WGS84 datum
|
71
|
+
def tile_lon_lat_bounds(tx, ty, zoom)
|
72
|
+
bounds = tile_bounds(tx, ty, zoom)
|
73
|
+
min_lon, min_lat = meters_to_lon_lat(bounds[0], bounds[1])
|
74
|
+
max_lon, max_lat = meters_to_lon_lat(bounds[2], bounds[3])
|
75
|
+
|
76
|
+
[min_lon, min_lat, max_lon, max_lat]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Resolution (meters/pixel) for given zoom level (measured at Equator)
|
80
|
+
def resolution(zoom)
|
81
|
+
@initial_resolution / (2**zoom)
|
82
|
+
end
|
83
|
+
|
84
|
+
# "Maximal scaledown zoom of the pyramid closest to the pixelSize.
|
85
|
+
def zoom_for_pixel_size(pixel_size)
|
86
|
+
(1..30).each do |i|
|
87
|
+
if pixel_size > resolution(i)
|
88
|
+
return i != 0 ? (i - 1) : 0
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Converts TMS tile coordinates to Google Tile coordinates
|
94
|
+
def google_tile(tx, ty, zoom)
|
95
|
+
[tx, (2**zoom - 1) - ty]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Converts TMS tile coordinates to Microsoft QuadTree
|
99
|
+
def quad_tree_key(tx, ty, zoom)
|
100
|
+
quad_key = ""
|
101
|
+
ty = (2**zoom - 1) - ty
|
102
|
+
i = zoom
|
103
|
+
while i > 0
|
104
|
+
digit = 0
|
105
|
+
mask = 1 << (i - 1)
|
106
|
+
digit += 1 if (tx & mask) != 0
|
107
|
+
digit += 2 if (ty & mask) != 0
|
108
|
+
quad_key += digit.to_s
|
109
|
+
i -= 1
|
110
|
+
end
|
111
|
+
quad_key
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: global_map_tiles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavier Delamotte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Ruby port of the script "Tiles à la Google Maps: Coordinates, Tile Bounds
|
14
|
+
and Projection" from http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/'
|
15
|
+
email:
|
16
|
+
- git@xade.eu
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".github/issue_template.md"
|
22
|
+
- ".github/pull_request_template.md"
|
23
|
+
- ".github/workflows/ci.yml"
|
24
|
+
- ".gitignore"
|
25
|
+
- ".rspec"
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/console
|
32
|
+
- bin/setup
|
33
|
+
- global_map_tiles.gemspec
|
34
|
+
- lib/global_map_tiles.rb
|
35
|
+
- lib/global_map_tiles/global_geodetic.rb
|
36
|
+
- lib/global_map_tiles/global_mercator.rb
|
37
|
+
- lib/global_map_tiles/version.rb
|
38
|
+
homepage: https://github.com/x4d3/global_map_tiles
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/x4d3/global_map_tiles
|
43
|
+
source_code_uri: https://github.com/x4d3/global_map_tiles
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.3.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.7.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Ruby port of globalmaptiles.py
|
64
|
+
test_files: []
|