Class: GeoRuby::Rtree::STRBuilder
- Inherits:
-
Object
- Object
- GeoRuby::Rtree::STRBuilder
- Defined in:
- lib/georuby-ext/georuby/rtree.rb
Defined Under Namespace
Classes: Slice
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#node_size ⇒ Object
Returns the value of attribute node_size.
Instance Method Summary collapse
-
#initialize(elements, node_size = 2) ⇒ STRBuilder
constructor
A new instance of STRBuilder.
- #leaf_nodes ⇒ Object
- #leaf_nodes_count ⇒ Object
- #root_node ⇒ Object
- #slice_size ⇒ Object
- #slices ⇒ Object
- #sort_x ⇒ Object
- #to_rtree ⇒ Object
Constructor Details
#initialize(elements, node_size = 2) ⇒ STRBuilder
Returns a new instance of STRBuilder.
19 20 21 22 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 19 def initialize(elements, node_size = 2) @elements = elements @node_size = node_size end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
17 18 19 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 17 def elements @elements end |
#node_size ⇒ Object
Returns the value of attribute node_size.
17 18 19 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 17 def node_size @node_size end |
Instance Method Details
#leaf_nodes ⇒ Object
28 29 30 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 28 def leaf_nodes slices.collect(&:nodes).flatten end |
#leaf_nodes_count ⇒ Object
60 61 62 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 60 def leaf_nodes_count (elements.count / node_size.to_f).ceil end |
#root_node ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 32 def root_node nodes = leaf_nodes while nodes.many? nodes = [].tap do |parent_nodes| nodes.each_slice(node_size) do |children| parent_nodes << Node.new(children) end end end nodes.first end |
#slice_size ⇒ Object
64 65 66 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 64 def slice_size Math.sqrt(leaf_nodes_count).ceil end |
#slices ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 46 def slices [].tap do |slices| sort_x.each_slice(slice_size) do |slice_elements| slices << Slice.new(slice_elements, node_size) end end end |
#sort_x ⇒ Object
54 55 56 57 58 |
# File 'lib/georuby-ext/georuby/rtree.rb', line 54 def sort_x elements.sort_by do |element| element.bounds.center.x end end |