Class: Geospatial::Map
- Inherits:
-
Object
- Object
- Geospatial::Map
- Defined in:
- lib/geospatial/map.rb,
lib/geospatial/map/index.rb
Defined Under Namespace
Classes: Index
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(object) ⇒ Object
- #bounds ⇒ Object
- #count ⇒ Object
- #filter_for(region, **options) ⇒ Object
- #hash_for_coordinates(coordinates) ⇒ Object
-
#index ⇒ Object
serialize :point, Map.for_earth.index.
-
#initialize(curve) ⇒ Map
constructor
A new instance of Map.
- #order ⇒ Object
- #point_for_coordinates(coordinates, object = nil) ⇒ Object
- #point_for_hash(hash) ⇒ Object
- #point_for_object(object) ⇒ Object
- #query(region, **options) ⇒ Object
- #sort! ⇒ Object
- #traverse(region, depth: 0) ⇒ Object
Constructor Details
#initialize(curve) ⇒ Map
Returns a new instance of Map.
61 62 63 64 65 |
# File 'lib/geospatial/map.rb', line 61 def initialize(curve) @curve = curve @points = [] @bounds = nil end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
82 83 84 |
# File 'lib/geospatial/map.rb', line 82 def points @points end |
Class Method Details
.for_earth(order = 20) ⇒ Object
57 58 59 |
# File 'lib/geospatial/map.rb', line 57 def self.for_earth(order = 20) self.new(Hilbert::Curve.new(Dimensions.for_earth, order)) end |
Instance Method Details
#<<(object) ⇒ Object
100 101 102 103 104 |
# File 'lib/geospatial/map.rb', line 100 def << object @points << point_for_coordinates(object.to_a, object) return self end |
#bounds ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/geospatial/map.rb', line 71 def bounds unless @bounds origin = @curve.origin size = @curve.size @bounds = Box.new(origin, size) end return @bounds end |
#count ⇒ Object
106 107 108 |
# File 'lib/geospatial/map.rb', line 106 def count @points.count end |
#filter_for(region, **options) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/geospatial/map.rb', line 143 def filter_for(region, **) filter = Filter.new traverse(region, **) do |child, prefix, order| filter.add(prefix, order) end return filter end |
#hash_for_coordinates(coordinates) ⇒ Object
84 85 86 |
# File 'lib/geospatial/map.rb', line 84 def hash_for_coordinates(coordinates) @curve.map(coordinates) end |
#index ⇒ Object
serialize :point, Map.for_earth.index
49 50 51 52 53 54 55 |
# File 'lib/geospatial/map/index.rb', line 49 def index klass = Class.new(Index) klass.map = self return klass end |
#order ⇒ Object
67 68 69 |
# File 'lib/geospatial/map.rb', line 67 def order @curve.order end |
#point_for_coordinates(coordinates, object = nil) ⇒ Object
92 93 94 |
# File 'lib/geospatial/map.rb', line 92 def point_for_coordinates(coordinates, object = nil) Point.new(self, coordinates, object) end |
#point_for_hash(hash) ⇒ Object
88 89 90 |
# File 'lib/geospatial/map.rb', line 88 def point_for_hash(hash) Point.new(self, @curve.unmap(hash)) end |
#point_for_object(object) ⇒ Object
96 97 98 |
# File 'lib/geospatial/map.rb', line 96 def point_for_object(object) Point.new(self, object.to_a, object) end |
#query(region, **options) ⇒ Object
114 115 116 117 118 |
# File 'lib/geospatial/map.rb', line 114 def query(region, **) filter = filter_for(region, **) return filter.apply(@points).map(&:object) end |
#sort! ⇒ Object
110 111 112 |
# File 'lib/geospatial/map.rb', line 110 def sort! @points.sort_by!(&:hash) end |
#traverse(region, depth: 0) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/geospatial/map.rb', line 120 def traverse(region, depth: 0) @curve.traverse do |child_origin, child_size, prefix, order| child = Box.new(Vector.elements(child_origin), Vector.elements(child_size)) # puts "Considering (order=#{order}) #{child.inspect}..." if region.intersect?(child) if order == depth # at bottom # puts "at bottom -> found prefix #{prefix.to_s(2)} (#{child.inspect})" yield(child, prefix, order); :skip elsif region.include?(child) # puts "include child -> found prefix #{prefix.to_s(2)} (#{child.inspect})" yield(child, prefix, order); :skip else # puts "going deeper..." end else # puts "out of bounds." :skip end end end |