Module: H3::Indexing
Overview
Indexing functions.
Coordinates are returned in degrees, in the form
[latitude, longitude]
Instance Method Summary collapse
-
#from_geo_coordinates(coords, resolution) ⇒ Integer
Derive H3 index for the given set of coordinates.
-
#geo_to_h3(coords, resolution) ⇒ Object
deprecated
Deprecated.
Please use #from_geo_coordinates instead.
-
#h3_to_geo(h3_index) ⇒ Object
deprecated
Deprecated.
Please use #to_geo_coordinates instead.
-
#h3_to_geo_boundary(h3_index) ⇒ Object
deprecated
Deprecated.
Please use #to_boundary instead.
-
#to_boundary(h3_index) ⇒ Array<Array<Integer>>
Derive the geographical boundary as coordinates for a given H3 index.
-
#to_geo_coordinates(h3_index) ⇒ Array<Integer>
Derive coordinates for a given H3 index.
Methods included from Bindings::Base
Instance Method Details
#from_geo_coordinates(coords, resolution) ⇒ Integer
Derive H3 index for the given set of coordinates.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/h3/indexing.rb', line 23 def from_geo_coordinates(coords, resolution) raise ArgumentError unless coords.is_a?(Array) && coords.count == 2 lat, lon = coords if lat > 90 || lat < -90 || lon > 180 || lon < -180 raise(ArgumentError, "Invalid coordinates") end coords = GeoCoord.new coords[:lat] = degs_to_rads(lat) coords[:lon] = degs_to_rads(lon) Bindings::Private.geo_to_h3(coords, resolution) end |
#geo_to_h3(coords, resolution) ⇒ Object
Please use #from_geo_coordinates instead.
39 40 41 |
# File 'lib/h3/indexing.rb', line 39 def geo_to_h3(coords, resolution) from_geo_coordinates(coords, resolution) end |
#h3_to_geo(h3_index) ⇒ Object
Please use #to_geo_coordinates instead.
62 63 64 |
# File 'lib/h3/indexing.rb', line 62 def h3_to_geo(h3_index) to_geo_coordinates(h3_index) end |
#h3_to_geo_boundary(h3_index) ⇒ Object
Please use #to_boundary instead.
94 95 96 |
# File 'lib/h3/indexing.rb', line 94 def h3_to_geo_boundary(h3_index) to_boundary(h3_index) end |
#to_boundary(h3_index) ⇒ Array<Array<Integer>>
Derive the geographical boundary as coordinates for a given H3 index.
This will be a set of 6 coordinate pairs matching the vertexes of the hexagon represented by the given H3 index.
If the H3 index is a pentagon, there will be only 5 coordinate pairs returned.
85 86 87 88 89 90 91 |
# File 'lib/h3/indexing.rb', line 85 def to_boundary(h3_index) geo_boundary = GeoBoundary.new Bindings::Private.h3_to_geo_boundary(h3_index, geo_boundary) geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d| [rads_to_degs(d[:lat]), rads_to_degs(d[:lon])] end end |
#to_geo_coordinates(h3_index) ⇒ Array<Integer>
Derive coordinates for a given H3 index.
The coordinates map to the centre of the hexagon at the given index.
55 56 57 58 59 |
# File 'lib/h3/indexing.rb', line 55 def to_geo_coordinates(h3_index) coords = GeoCoord.new Bindings::Private.h3_to_geo(h3_index, coords) [rads_to_degs(coords[:lat]), rads_to_degs(coords[:lon])] end |