Module: H3::UnidirectionalEdges

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

Overview

Unidirectional edge functions

Instance Method Summary collapse

Methods included from Bindings::Base

attach_predicate_function, extended

Instance Method Details

#destination_from_unidirectional_edge(edge) ⇒ Integer

Derive destination H3 index from edge.

Examples:

Get destination index from edge

H3.destination_from_unidirectional_edge(1266218516299644927)
617700169961177087

Parameters:

  • edge (Integer)

    H3 edge index

Returns:

  • (Integer)

    H3 index



66
67
68
69
# File 'lib/h3/unidirectional_edges.rb', line 66

attach_function :destination_from_unidirectional_edge,
:getDestinationH3IndexFromUnidirectionalEdge,
%i[h3_index],
:h3_index

#neighbors?(origin, destination) ⇒ Boolean

Determine whether two H3 indexes are neighbors.

Examples:

Check two H3 indexes

H3.neighbors?(617700169958293503, 617700169958031359)
true

Parameters:

  • origin (Integer)

    Origin H3 index

  • destination (Integer)

    Destination H3 index

Returns:

  • (Boolean)

    True if indexes are neighbors



20
# File 'lib/h3/unidirectional_edges.rb', line 20

attach_predicate_function :neighbors?, :h3IndexesAreNeighbors, %i[h3_index h3_index], :bool

#origin_and_destination_from_unidirectional_edge(edge) ⇒ Array<Integer>

Derive origin and destination H3 indexes from edge.

Returned in the form

[origin, destination]

Examples:

Get origin and destination indexes from edge

H3.origin_and_destination_from_unidirectional_edge(1266218516299644927)
[617700169958293503, 617700169961177087]

Parameters:

  • edge (Integer)

    H3 edge index

Returns:

  • (Array<Integer>)

    H3 index array.



100
101
102
103
104
105
# File 'lib/h3/unidirectional_edges.rb', line 100

def origin_and_destination_from_unidirectional_edge(edge)
  max_hexagons = 2
  out = H3Indexes.of_size(max_hexagons)
  Bindings::Private.h3_indexes_from_unidirectional_edge(edge, out)
  out.read
end

#origin_from_unidirectional_edge(edge) ⇒ Integer

Derive origin H3 index from edge.

Examples:

Get origin index from edge

H3.origin_from_unidirectional_edge(1266218516299644927)
617700169958293503

Parameters:

  • edge (Integer)

    H3 edge index

Returns:

  • (Integer)

    H3 index



82
83
84
85
# File 'lib/h3/unidirectional_edges.rb', line 82

attach_function :origin_from_unidirectional_edge,
:getOriginH3IndexFromUnidirectionalEdge,
%i[h3_index],
:h3_index

#unidirectional_edge(origin, destination) ⇒ Integer

Derives the H3 index of the edge from the given H3 indexes.

Examples:

Derive the H3 edge index between two H3 indexes

H3.unidirectional_edge(617700169958293503, 617700169958031359)
1626506486489284607

Parameters:

  • origin (Integer)

    H3 index

  • destination (Integer)

    H3 index

Returns:

  • (Integer)

    H3 edge index



50
51
52
53
# File 'lib/h3/unidirectional_edges.rb', line 50

attach_function :unidirectional_edge,
:getH3UnidirectionalEdge,
%i[h3_index h3_index],
:h3_index

#unidirectional_edge_boundary(edge) ⇒ Array<Array<Float>>

Derive coordinates for edge boundary.

Examples:

H3.unidirectional_edge_boundary(612933930963697663)
[
  [68.92995788193981, 31.831280499087402], [69.39359648991828, 62.345344956509784],
  [76.163042830191, 94.14309010184775], [87.36469532319619, 145.5581976913368],
  [81.27137179020497, -34.75841798028461], [73.31022368544393, 0.32561035194326043]
]

Parameters:

  • edge (Integer)

    H3 edge index

Returns:

  • (Array<Array<Float>>)

    Edge boundary coordinates for a hexagon



139
140
141
142
143
144
145
# File 'lib/h3/unidirectional_edges.rb', line 139

def unidirectional_edge_boundary(edge)
  geo_boundary = GeoBoundary.new
  Bindings::Private.h3_unidirectional_edge_boundary(edge, geo_boundary)
  geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d|
    [rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
  end
end

#unidirectional_edge_valid?(h3_index) ⇒ Boolean

Determine whether the given H3 index represents an edge.

Examples:

Check if H3 index is a valid unidirectional edge.

H3.unidirectional_edge_valid?(1266218516299644927)
true

Parameters:

  • h3_index (Integer)

    H3 index

Returns:

  • (Boolean)

    True if H3 index is a valid unidirectional edge



33
34
35
36
# File 'lib/h3/unidirectional_edges.rb', line 33

attach_predicate_function :unidirectional_edge_valid?,
:h3UnidirectionalEdgeIsValid,
%i[h3_index],
:bool

#unidirectional_edges_from_hexagon(origin) ⇒ Array<Integer>

Derive unidirectional edges for a H3 index.

Examples:

Get unidirectional indexes from hexagon

H3.unidirectional_edges_from_hexagon(612933930963697663)
[
  1261452277305049087, 1333509871342977023, 1405567465380904959,
  1477625059418832895, 1549682653456760831, 1621740247494688767
]

Parameters:

  • origin (Integer)

    H3 index

Returns:

  • (Array<Integer>)

    H3 index array.



119
120
121
122
123
124
# File 'lib/h3/unidirectional_edges.rb', line 119

def unidirectional_edges_from_hexagon(origin)
  max_edges = 6
  out = H3Indexes.of_size(max_edges)
  Bindings::Private.h3_unidirectional_edges_from_hexagon(origin, out)
  out.read
end