Module: H3::Miscellaneous

Extended by:
Bindings::Base
Included in:
H3
Defined in:
lib/h3/miscellaneous.rb

Overview

Miscellaneous functions.

Instance Method Summary collapse

Methods included from Bindings::Base

attach_predicate_function, extended

Instance Method Details

#base_cell_countInteger

Returns the number of resolution 0 hexagons (base cells).

Examples:

Return the number of base cells

H3.base_cell_count
122

Returns:

  • (Integer)

    The number of resolution 0 hexagons (base cells).



108
# File 'lib/h3/miscellaneous.rb', line 108

attach_function :base_cell_count, :res0IndexCount, [], :int

#base_cellsArray<Integer>

Returns all resolution 0 hexagons (base cells).

Examples:

Return all base cells.

H3.base_cells
[576495936675512319, 576531121047601151, ..., 580753245698260991]

Returns:

  • (Array<Integer>)

    All resolution 0 hexagons (base cells).



228
229
230
231
232
# File 'lib/h3/miscellaneous.rb', line 228

def base_cells
  out = H3Indexes.of_size(base_cell_count)
  Bindings::Private.res_0_indexes(out)
  out.read
end

#cell_area_km2Double

Area of a given cell expressed in km squared

Examples:

Return the area of the cell

H3.cell_area_km2(617700169958293503)
0.10939818864648902

Returns:

  • (Double)

    Area of cell in km2



142
# File 'lib/h3/miscellaneous.rb', line 142

attach_function :cell_area_km2, :cellAreaKm2, %i[h3_index], :double

#cell_area_m2Double

Area of a given cell expressed in metres squared

Examples:

Return the area of the cell

H3.cell_area_m2(617700169958293503)
109398.18864648901

Returns:

  • (Double)

    Area of cell in metres squared



153
# File 'lib/h3/miscellaneous.rb', line 153

attach_function :cell_area_m2, :cellAreaM2, %i[h3_index], :double

#cell_area_rads2Double

Area of a given cell expressed in radians squared

Examples:

Return the area of the cell

H3.cell_area_rads2(617700169958293503)
2.6952182709835757e-09

Returns:

  • (Double)

    Area of cell in rads2



131
# File 'lib/h3/miscellaneous.rb', line 131

attach_function :cell_area_rads2, :cellAreaRads2, %i[h3_index], :double

#degs_to_rads(degs) ⇒ Float

Convert a number expressed in degrees to its equivalent in radians.

Examples:

Convert degrees value to radians.

H3.degs_to_rads(19.61922082086965)
0.34242

Parameters:

  • degs (Float)

    Value expressed in degrees.

Returns:

  • (Float)

    Value expressed in radians.



19
# File 'lib/h3/miscellaneous.rb', line 19

attach_function :degs_to_rads, :degsToRads, %i[double], :double

#edge_length_km(resolution) ⇒ Float

Derive the length of a hexagon edge in kilometres at the given resolution.

Examples:

Derive length of edge in kilometres

H3.edge_length_km(3)
59.81085794

Parameters:

  • resolution (Integer)

    Resolution.

Returns:

  • (Float)

    Length of edge in kilometres



32
# File 'lib/h3/miscellaneous.rb', line 32

attach_function :edge_length_km, :edgeLengthKm, [Resolution], :double

#edge_length_m(resolution) ⇒ Float

Derive the length of a hexagon edge in metres at the given resolution.

Examples:

Derive length of edge in metres

H3.edge_length_m(6)
3229.482772

Parameters:

  • resolution (Integer)

    Resolution.

Returns:

  • (Float)

    Length of edge in metres



45
# File 'lib/h3/miscellaneous.rb', line 45

attach_function :edge_length_m, :edgeLengthM, [Resolution], :double

#exact_edge_length_kmDouble

Exact length of edge in kilometres

Examples:

Return the edge length

H3.exact_edge_length_km(1266218516299644927)
3.287684056071637e-05

Returns:

  • (Double)

    Edge length in kilometres



175
# File 'lib/h3/miscellaneous.rb', line 175

attach_function :exact_edge_length_km, :exactEdgeLengthKm, %i[h3_index], :double

#exact_edge_length_mDouble

Exact length of edge in metres

Examples:

Return the edge length

H3.exact_edge_length_m(1266218516299644927)
3.287684056071637e-05

Returns:

  • (Double)

    Edge length in metres



186
# File 'lib/h3/miscellaneous.rb', line 186

attach_function :exact_edge_length_m, :exactEdgeLengthM, %i[h3_index], :double

#exact_edge_length_radsDouble

Exact length of edge in rads

Examples:

Return the edge length

H3.exact_edge_length_rads(1266218516299644927)
3.287684056071637e-05

Returns:

  • (Double)

    Edge length in rads



164
# File 'lib/h3/miscellaneous.rb', line 164

attach_function :exact_edge_length_rads, :exactEdgeLengthRads, %i[h3_index], :double

#hex_area_km2(resolution) ⇒ Float

Average hexagon area in square kilometres at the given resolution.

Examples:

Find the square kilometre size at resolution 5

H3.hex_area_km2(5)
252.9033645

Parameters:

  • resolution (Integer)

    Resolution.

Returns:

  • (Float)

    Average hexagon area in square kilometres.



58
# File 'lib/h3/miscellaneous.rb', line 58

attach_function :hex_area_km2, :hexAreaKm2, [Resolution], :double

#hex_area_m2(resolution) ⇒ Float

Average hexagon area in square metres at the given resolution.

Examples:

Find the square metre size at resolution 10

H3.hex_area_m2(10)
15047.5

Parameters:

  • resolution (Integer)

    Resolution.

Returns:

  • (Float)

    Average hexagon area in square metres.



71
# File 'lib/h3/miscellaneous.rb', line 71

attach_function :hex_area_m2, :hexAreaM2, [Resolution], :double

#hexagon_count(resolution) ⇒ Integer

Number of unique H3 indexes at the given resolution.

Examples:

Find number of hexagons at resolution 6

H3.hexagon_count(6)
14117882

Parameters:

  • resolution (Integer)

    Resolution.

Returns:

  • (Integer)

    Number of unique hexagons



84
# File 'lib/h3/miscellaneous.rb', line 84

attach_function :hexagon_count, :numHexagons, [Resolution], :ulong_long

#pentagon_countInteger

Number of pentagon H3 indexes per resolution. This is always 12, but provided as a convenience.

Examples:

Return the number of pentagons

H3.pentagon_count
12

Returns:

  • (Integer)

    The number of pentagons per resolution.



120
# File 'lib/h3/miscellaneous.rb', line 120

attach_function :pentagon_count, :pentagonIndexCount, [], :int

#pentagons(resolution) ⇒ Array<Integer>

Returns all pentagon indexes at the given resolution.

Examples:

Return all pentagons at resolution 4.

H3.pentagons(4)
[594615896891195391, 594967740612083711, ..., 598591730937233407]

Returns:

  • (Array<Integer>)

    All pentagon indexes at the given resolution.



241
242
243
244
245
# File 'lib/h3/miscellaneous.rb', line 241

def pentagons(resolution)
  out = H3Indexes.of_size(pentagon_count)
  Bindings::Private.get_pentagon_indexes(resolution, out)
  out.read
end

#point_distance_km(origin, destination) ⇒ Double

Returns the kilometres distance between two points.

Examples:

Return km distance.

H3.point_distance_km([41.3964809, 2.160444], [41.3870609, 2.164917])
1.1119334622766763

Returns:

  • (Double)

    KM distance between two points.



206
207
208
# File 'lib/h3/miscellaneous.rb', line 206

def point_distance_km(origin, destination)
  Bindings::Private.point_distance_km(*build_geocoords(origin, destination))
end

#point_distance_m(origin, destination) ⇒ Double

Returns the metre distance between two points.

Examples:

Return metre distance.

H3.point_distance_m([41.3964809, 2.160444], [41.3870609, 2.164917])
1111.9334622766764

Returns:

  • (Double)

    Metre distance between two points.



217
218
219
# File 'lib/h3/miscellaneous.rb', line 217

def point_distance_m(origin, destination)
  Bindings::Private.point_distance_m(*build_geocoords(origin, destination))
end

#point_distance_rads(origin, destination) ⇒ Double

Returns the radians distance between two points.

Examples:

Return radians distance.

H3.point_distance_rads([41.3964809, 2.160444], [41.3870609, 2.164917])
0.00017453024784008713

Returns:

  • (Double)

    Radians distance between two points.



195
196
197
# File 'lib/h3/miscellaneous.rb', line 195

def point_distance_rads(origin, destination)
  Bindings::Private.point_distance_rads(*build_geocoords(origin, destination))
end

#rads_to_degs(rads) ⇒ Float

Convert a number expressed in radians to its equivalent in degrees.

Examples:

Convert radians value to degrees.

H3.rads_to_degs(0.34242)
19.61922082086965

Parameters:

  • rads (Float)

    Value expressed in radians.

Returns:

  • (Float)

    Value expressed in degrees.



97
# File 'lib/h3/miscellaneous.rb', line 97

attach_function :rads_to_degs, :radsToDegs, %i[double], :double