Module: H3::Hierarchy
Overview
Hierarchical grid functions.
Instance Method Summary collapse
-
#center_child(h3_index, child_resolution) ⇒ Integer
Returns the center child (finer) index contained by the given index at the given resolution.
-
#children(h3_index, child_resolution) ⇒ Array<Integer>
Derive child hexagons contained within the hexagon at the given H3 index.
-
#compact(h3_set) ⇒ Array<Integer>
Compact a set of H3 indexes as best as possible.
-
#max_children(h3_index, child_resolution) ⇒ Integer
Derive maximum number of child hexagons possible at given resolution.
-
#max_uncompact_size(compacted_set, resolution) ⇒ Integer
Find the maximum uncompacted size of the given set of H3 indexes.
-
#parent(h3_index, parent_resolution) ⇒ Integer
Derive the parent hexagon which contains the hexagon at the given H3 index.
-
#uncompact(compacted_set, resolution) ⇒ Array<Integer>
Uncompact a set of H3 indexes to the given resolution.
Methods included from Bindings::Base
attach_predicate_function, extended
Instance Method Details
#center_child(h3_index, child_resolution) ⇒ Integer
Returns the center child (finer) index contained by the given index at the given resolution.
49 |
# File 'lib/h3/hierarchy.rb', line 49 attach_function :center_child, :h3ToCenterChild, [:h3_index, Resolution], :h3_index |
#children(h3_index, child_resolution) ⇒ Array<Integer>
Derive child hexagons contained within the hexagon at the given H3 index.
64 65 66 67 68 69 |
# File 'lib/h3/hierarchy.rb', line 64 def children(h3_index, child_resolution) max_children = max_children(h3_index, child_resolution) out = H3Indexes.of_size(max_children) Bindings::Private.h3_to_children(h3_index, child_resolution, out) out.read end |
#compact(h3_set) ⇒ Array<Integer>
Compact a set of H3 indexes as best as possible.
In the case where the set cannot be compacted, the set is returned unchanged.
121 122 123 124 125 126 127 128 |
# File 'lib/h3/hierarchy.rb', line 121 def compact(h3_set) h3_set = H3Indexes.with_contents(h3_set) out = H3Indexes.of_size(h3_set.size) failure = Bindings::Private.compact(h3_set, out, out.size) raise "Couldn't compact given indexes" if failure out.read end |
#max_children(h3_index, child_resolution) ⇒ Integer
Derive maximum number of child hexagons possible at given resolution.
34 |
# File 'lib/h3/hierarchy.rb', line 34 attach_function :max_children, :maxH3ToChildrenSize, [:h3_index, Resolution], :int |
#max_uncompact_size(compacted_set, resolution) ⇒ Integer
Find the maximum uncompacted size of the given set of H3 indexes.
89 90 91 92 93 94 |
# File 'lib/h3/hierarchy.rb', line 89 def max_uncompact_size(compacted_set, resolution) h3_set = H3Indexes.with_contents(compacted_set) size = Bindings::Private.max_uncompact_size(h3_set, compacted_set.size, resolution) raise(ArgumentError, "Couldn't estimate size. Invalid resolution?") if size.negative? size end |
#parent(h3_index, parent_resolution) ⇒ Integer
Derive the parent hexagon which contains the hexagon at the given H3 index.
20 |
# File 'lib/h3/hierarchy.rb', line 20 attach_function :parent, :h3ToParent, [:h3_index, Resolution], :h3_index |
#uncompact(compacted_set, resolution) ⇒ Array<Integer>
Uncompact a set of H3 indexes to the given resolution.
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/h3/hierarchy.rb', line 154 def uncompact(compacted_set, resolution) max_size = max_uncompact_size(compacted_set, resolution) out = H3Indexes.of_size(max_size) h3_set = H3Indexes.with_contents(compacted_set) failure = Bindings::Private.uncompact(h3_set, compacted_set.size, out, max_size, resolution) raise "Couldn't uncompact given indexes" if failure out.read end |