Module: H3::Hierarchy
Overview
Hierarchical grid functions.
Instance Method Summary collapse
-
#compact(h3_set) ⇒ Array<Integer>
Compact a set of H3 indexes as best as possible.
-
#h3_to_children(h3_index, child_resolution) ⇒ Array<Integer>
Derive child hexagons contained within the hexagon at the given H3 index.
-
#h3_to_parent(h3_index, parent_resolution) ⇒ Integer
Derive the parent hexagon which contains the hexagon at the given H3 index.
-
#max_h3_to_children_size(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.
-
#uncompact(compacted_set, resolution) ⇒ Array<Integer>
Uncompact a set of H3 indexes to the given resolution.
Methods included from Bindings::Base
Instance Method Details
#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.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/h3/hierarchy.rb', line 109 def compact(h3_set) h3_set = h3_set.uniq failure = false out = FFI::MemoryPointer.new(H3_INDEX, h3_set.size) FFI::MemoryPointer.new(H3_INDEX, h3_set.size) do |hexagons_ptr| hexagons_ptr.write_array_of_ulong_long(h3_set) failure = Bindings::Private.compact(hexagons_ptr, out, h3_set.size) end raise "Couldn't compact given indexes" if failure out.read_array_of_ulong_long(h3_set.size).reject(&:zero?) end |
#h3_to_children(h3_index, child_resolution) ⇒ Array<Integer>
Derive child hexagons contained within the hexagon at the given H3 index.
49 50 51 52 53 54 |
# File 'lib/h3/hierarchy.rb', line 49 def h3_to_children(h3_index, child_resolution) max_children = max_h3_to_children_size(h3_index, child_resolution) h3_children = FFI::MemoryPointer.new(H3_INDEX, max_children) Bindings::Private.h3_to_children(h3_index, child_resolution, h3_children) h3_children.read_array_of_ulong_long(max_children).reject(&:zero?) end |
#h3_to_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 :h3_to_parent, :h3ToParent, [ :h3_index, :int ], :h3_index |
#max_h3_to_children_size(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_h3_to_children_size, :maxH3ToChildrenSize, [ :h3_index, :int ], :int |
#max_uncompact_size(compacted_set, resolution) ⇒ Integer
Find the maximum uncompacted size of the given set of H3 indexes.
74 75 76 77 78 79 80 81 82 |
# File 'lib/h3/hierarchy.rb', line 74 def max_uncompact_size(compacted_set, resolution) compacted_set = compacted_set.uniq FFI::MemoryPointer.new(H3_INDEX, compacted_set.size) do |hexagons_ptr| hexagons_ptr.write_array_of_ulong_long(compacted_set) size = Bindings::Private.max_uncompact_size(hexagons_ptr, compacted_set.size, resolution) raise(ArgumentError, "Couldn't estimate size. Invalid resolution?") if size < 0 return size end end |
#uncompact(compacted_set, resolution) ⇒ Array<Integer>
Uncompact a set of H3 indexes to the given resolution.
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/h3/hierarchy.rb', line 146 def uncompact(compacted_set, resolution) max_size = max_uncompact_size(compacted_set, resolution) failure = false out = FFI::MemoryPointer.new(H3_INDEX, max_size) FFI::MemoryPointer.new(H3_INDEX, compacted_set.size) do |hexagons_ptr| hexagons_ptr.write_array_of_ulong_long(compacted_set) failure = Bindings::Private.uncompact(hexagons_ptr, compacted_set.size, out, max_size, resolution) end raise "Couldn't uncompact given indexes" if failure out.read_array_of_ulong_long(max_size).reject(&:zero?) end |