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

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


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

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

#h3_indexes_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.h3_indexes_from_unidirectional_edge(1266218516299644927)
[617700169958293503, 617700169961177087]


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

def h3_indexes_from_unidirectional_edge(edge)
  max_hexagons = 2
  origin_destination = FFI::MemoryPointer.new(:ulong_long, max_hexagons)
  Bindings::Private.h3_indexes_from_unidirectional_edge(edge, origin_destination)
  origin_destination.read_array_of_ulong_long(max_hexagons).reject(&:zero?)
end

#h3_indexes_neighbors?(origin, destination) ⇒ Boolean

Determine whether two H3 indexes are neighbors.

Examples:

Check two H3 indexes

H3.h3_indexes_neighbors?(617700169958293503, 617700169958031359)
true


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

attach_function :h3_indexes_neighbors, :h3IndexesAreNeighbors, [ :h3_index, :h3_index ], :bool

#h3_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.h3_unidirectional_edge(617700169958293503, 617700169958031359)
1626506486489284607


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

attach_function :h3_unidirectional_edge,
:getH3UnidirectionalEdge,
[ :h3_index, :h3_index ],
:h3_index

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

Derive coordinates for edge boundary.

Examples:

H3.h3_unidirectional_edge_boundary(1266218516299644927)
[
  [37.77820687262237, -122.41971895414808],
  [37.77652420699321, -122.42079024541876]
]


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

def h3_unidirectional_edge_boundary(edge)
  geo_boundary = Bindings::Structs::GeoBoundary.new
  Bindings::Private.h3_unidirectional_edge_boundary(edge, geo_boundary)
  geo_boundary[:verts].take(geo_boundary[:num_verts] * 2).map do |d|
    rads_to_degs(d)
  end.each_slice(2).to_a
end

#h3_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.h3_unidirectional_edge_valid?(1266218516299644927)
true


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

attach_function :h3_unidirectional_edge_valid,
:h3UnidirectionalEdgeIsValid,
[ :h3_index ],
:bool

#h3_unidirectional_edges_from_hexagon(origin) ⇒ Array<Integer>

Derive unidirectional edges for a H3 index.

Examples:

Get unidirectional indexes from hexagon

H3.h3_unidirectional_edges_from_hexagon(1266218516299644927)
[
  1266218516299644927, 1338276110337572863, 1410333704375500799,
  1482391298413428735, 1554448892451356671, 1626506486489284607
]


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

def h3_unidirectional_edges_from_hexagon(origin)
  max_edges = 6
  edges = FFI::MemoryPointer.new(:ulong_long, max_edges)
  Bindings::Private.h3_unidirectional_edges_from_hexagon(origin, edges)
  edges.read_array_of_ulong_long(max_edges).reject(&:zero?)
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


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

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