Module: Wukong::Geolocated::ByCoordinates
- Extended by:
- Gorillib::Concern
- Defined in:
- lib/wu/geo/geolocated.rb
Overview
field :longitude, type: Float, description: “Longitude (X) of a point, in decimal degrees” field :latitude, type: Float, description: “Latitude (Y) of a point, in decimal degrees” field :zoom_level, type: Integer, description: “Zoom level of tile to fetch. An integer between 0 (world) and 16 or so” field :quadkey, type: String, description: “Quadkey of tile, eg 002313012” field :tile_x, type: Integer, description: “Tile X index, an integer between 0 and 2^zoom_level - 1” field :tile_y, type: Integer, description: “Tile Y index, an integer between 0 and 2^zoom_level - 1”
Instance Method Summary collapse
- #bbox_for_radius(radius) ⇒ Object
- #lng_lat ⇒ Object
-
#packed_qk ⇒ Object
the packed quadkey is the integer formed by interleaving the bits of tile_x with tile_y:.
-
#quadkey(zl) ⇒ Object
The quadkey is a string of 2-bit tile selectors for a quadtile.
-
#tile_x(zl) ⇒ Integer
X index of the tile this object lies on at given zoom level.
-
#tile_xf(zl) ⇒ Float
X index of the tile this object lies on at given zoom level.
-
#tile_xy(zl) ⇒ Float
Tile coordinates
(x,y)
for this object at given zoom level. -
#tile_y(zl) ⇒ Integer
Y index of the tile this object lies on at given zoom level.
-
#tile_yf(zl) ⇒ Float
Y index of the tile this object lies on at given zoom level.
Instance Method Details
#bbox_for_radius(radius) ⇒ Object
93 |
# File 'lib/wu/geo/geolocated.rb', line 93 def bbox_for_radius(radius) ; Wukong::Geolocated.lng_lat_rad_to_bbox(longitude, latitude, radius) ; end |
#lng_lat ⇒ Object
90 |
# File 'lib/wu/geo/geolocated.rb', line 90 def lng_lat ; [longitude, latitude] ; end |
#packed_qk ⇒ Object
the packed quadkey is the integer formed by interleaving the bits of tile_x with tile_y:
tile_x 58 binary 0 0 1 1 1 0 1 0
tile_y 105 binary 0 1 1 0 1 0 0 1
interleaved binary 00 10 11 01 11 00 01 10
quadkey 0 2 3 1 3 0 1 2 # "02313012"
(see quadkey
for more.)
At zoom level 15, the packed quadkey is a 30-bit unsigned integer – meaning you can store it in a pig int
; for languages with an unsigned
int
type, you can go to zoom level 16 before you have to use a less-efficient type. Zoom level 15 has a resolution of about one tile per kilometer (about 1.25 km/tile near the equator; 0.75 km/tile at London’s latitude). It takes 1 billion tiles to tile the world at that scale. Ruby’s integer type goes up to 60 bits, enough for any practical zoom level.
75 |
# File 'lib/wu/geo/geolocated.rb', line 75 def packed_qk ; Wukong::Geolocated.tile_xy_zl_to_packed_qk(tile_x(zl), tile_y(zl), zl) ; end |
#quadkey(zl) ⇒ Object
The quadkey is a string of 2-bit tile selectors for a quadtile
Interesting quadkey properties:
-
The quadkey length is its zoom level
-
To zoom out (lower zoom level, larger quadtile), just truncate the quadkey: austin at ZL=8 has quadkey “02313012”; at ZL=3, “023”
-
Nearby points typically have “nearby” quadkeys: up to the smallest tile that contains both, their quadkeys will have a common prefix. If you sort your records by quadkey, - Nearby points are nearby-ish on disk. (hello, HBase/Cassandra database owners!) This allows efficient lookup and caching of “popular” regions or repeated queries in an area. - the tiles covering a region can be covered by a limited, enumerable set of range scans. For map-reduce programmers, this leads to very efficient reducers
-
The quadkey is the bit-interleaved combination of its tile ids:
tile_x 58 binary 0 0 1 1 1 0 1 0 tile_y 105 binary 0 1 1 0 1 0 0 1 interleaved binary 00 10 11 01 11 00 01 10 quadkey 0 2 3 1 3 0 1 2 # "02313012"
55 |
# File 'lib/wu/geo/geolocated.rb', line 55 def quadkey(zl) ; Wukong::Geolocated.tile_xy_zl_to_quadkey( tile_x(zl), tile_y(zl), zl) ; end |
#tile_x(zl) ⇒ Integer
Returns x index of the tile this object lies on at given zoom level.
82 |
# File 'lib/wu/geo/geolocated.rb', line 82 def tile_x(zl) ; tile_xf(zl).floor ; end |
#tile_xf(zl) ⇒ Float
Returns x index of the tile this object lies on at given zoom level.
78 |
# File 'lib/wu/geo/geolocated.rb', line 78 def tile_xf(zl) ; Wukong::Geolocated.lng_zl_to_tile_xf(longitude, zl) ; end |
#tile_xy(zl) ⇒ Float
Returns tile coordinates (x,y)
for this object at given zoom level.
87 |
# File 'lib/wu/geo/geolocated.rb', line 87 def tile_xy(zl) ; [tile_x(xl), tile_y(zl)] ; end |
#tile_y(zl) ⇒ Integer
Returns y index of the tile this object lies on at given zoom level.
84 |
# File 'lib/wu/geo/geolocated.rb', line 84 def tile_y(zl) ; tile_yf(zl).floor ; end |
#tile_yf(zl) ⇒ Float
Returns y index of the tile this object lies on at given zoom level.
80 |
# File 'lib/wu/geo/geolocated.rb', line 80 def tile_yf(zl) ; Wukong::Geolocated.lat_zl_to_tile_yf(latitude, zl) ; end |