Module: H3::Regions
Overview
Region functions.
Instance Method Summary collapse
-
#h3_set_to_linked_geo(h3_indexes) ⇒ Array<Array<Array<Float>>>
Derive a nested array of coordinates from a list of H3 indexes.
-
#max_polyfill_size(geo_polygon, resolution) ⇒ Integer
Derive the maximum number of H3 indexes that could be returned from the input.
-
#polyfill(geo_polygon, resolution) ⇒ Array<Integer>
Derive a list of H3 indexes that fall within a given geo polygon structure.
Methods included from Bindings::Base
Instance Method Details
#h3_set_to_linked_geo(h3_indexes) ⇒ Array<Array<Array<Float>>>
Derive a nested array of coordinates from a list of H3 indexes.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/h3/regions.rb', line 137 def h3_set_to_linked_geo(h3_indexes) h3_indexes.uniq! linked_geo_polygon = Bindings::Structs::LinkedGeoPolygon.new FFI::MemoryPointer.new(H3_INDEX, h3_indexes.size) do |hexagons_ptr| hexagons_ptr.write_array_of_ulong_long(h3_indexes) Bindings::Private.h3_set_to_linked_geo(hexagons_ptr, h3_indexes.size, linked_geo_polygon) end extract_linked_geo_polygon(linked_geo_polygon).first end |
#max_polyfill_size(geo_polygon, resolution) ⇒ Integer
Derive the maximum number of H3 indexes that could be returned from the input.
50 51 52 53 |
# File 'lib/h3/regions.rb', line 50 def max_polyfill_size(geo_polygon, resolution) geo_polygon = geo_json_to_coordinates(geo_polygon) if geo_polygon.is_a?(String) Bindings::Private.max_polyfill_size(build_polygon(geo_polygon), resolution) end |
#polyfill(geo_polygon, resolution) ⇒ Array<Integer>
Derive a list of H3 indexes that fall within a given geo polygon structure.
103 104 105 106 107 108 109 |
# File 'lib/h3/regions.rb', line 103 def polyfill(geo_polygon, resolution) geo_polygon = geo_json_to_coordinates(geo_polygon) if geo_polygon.is_a?(String) max_size = max_polyfill_size(geo_polygon, resolution) out = FFI::MemoryPointer.new(H3_INDEX, max_size) Bindings::Private.polyfill(build_polygon(geo_polygon), resolution, out) out.read_array_of_ulong_long(max_size).reject(&:zero?) end |