Class: PbfReverseGeocoder::TileCalculator
- Inherits:
-
Object
- Object
- PbfReverseGeocoder::TileCalculator
- Defined in:
- lib/pbf_reverse_geocoder/tile_calculator.rb
Constant Summary collapse
- ZOOM =
ズームレベル10固定(@geoloniaと同じ、約30km四方)
10
Class Method Summary collapse
-
.lng_lat_to_tile(lng, lat) ⇒ Array<Integer>
Google XYZ タイル座標を計算 Web Mercator投影を使用.
-
.tile_path(x, y, zoom, tiles_dir) ⇒ Pathname
タイルのファイルパスを生成.
Class Method Details
.lng_lat_to_tile(lng, lat) ⇒ Array<Integer>
Google XYZ タイル座標を計算Web Mercator投影を使用
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pbf_reverse_geocoder/tile_calculator.rb', line 22 def self.lng_lat_to_tile(lng, lat) # global-mercator の pointToTileFraction ロジック n = 2.0**ZOOM lat_rad = lat * Math::PI / 180.0 sin_lat = Math.sin(lat_rad) # X座標(経度ベース) x = ((lng + 180.0) / 360.0 * n).floor # Y座標(緯度ベース、メルカトル投影) y = ((0.5 - (0.25 * Math.log((1 + sin_lat) / (1 - sin_lat)) / Math::PI)) * n).floor [x, y, ZOOM] end |
.tile_path(x, y, zoom, tiles_dir) ⇒ Pathname
タイルのファイルパスを生成
48 49 50 51 |
# File 'lib/pbf_reverse_geocoder/tile_calculator.rb', line 48 def self.tile_path(x, y, zoom, tiles_dir) require 'pathname' Pathname.new(tiles_dir).join(zoom.to_s, x.to_s, "#{y}.pbf") end |