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).



129
130
131
132
133
# File 'lib/h3/miscellaneous.rb', line 129

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

#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

#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.



142
143
144
145
146
# File 'lib/h3/miscellaneous.rb', line 142

def pentagons(resolution)
  out = H3Indexes.of_size(pentagon_count)
  Bindings::Private.get_pentagon_indexes(resolution, out)
  out.read
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