Class: TG::Geometry::Registry
- Inherits:
-
Object
- Object
- TG::Geometry::Registry
- Defined in:
- lib/tg/geometry/registry.rb
Constant Summary collapse
- DEFAULT_INDEX_OPTIONS =
{ via: :geojson, strategy: :rtree, predicate: :covers, geometry_index: :ystripes }.freeze
Instance Attribute Summary collapse
-
#index_options ⇒ Object
readonly
Returns the value of attribute index_options.
Class Method Summary collapse
- .active_record_source(scope, id:, geometry:, batch_size: 1_000) ⇒ Object
- .index_options(**options) ⇒ Object
- .source(&block) ⇒ Object
Instance Method Summary collapse
- #bbox ⇒ Object
- #covering_ids(lon, lat) ⇒ Object
- #covering_ids_batch_packed(binary_string) ⇒ Object
- #find_covering(lon, lat) ⇒ Object
- #index ⇒ Object
-
#initialize(entries: nil, source: nil, **index_options) ⇒ Registry
constructor
A new instance of Registry.
- #intersecting_rect(min_x, min_y, max_x, max_y) ⇒ Object
- #loaded? ⇒ Boolean
- #reload! ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(entries: nil, source: nil, **index_options) ⇒ Registry
Returns a new instance of Registry.
49 50 51 52 53 54 55 |
# File 'lib/tg/geometry/registry.rb', line 49 def initialize(entries: nil, source: nil, **) @entries = entries @source = source @index_options = self.class..merge().freeze @reload_mutex = Mutex.new @index = nil end |
Instance Attribute Details
#index_options ⇒ Object (readonly)
Returns the value of attribute index_options.
47 48 49 |
# File 'lib/tg/geometry/registry.rb', line 47 def @index_options end |
Class Method Details
.active_record_source(scope, id:, geometry:, batch_size: 1_000) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tg/geometry/registry.rb', line 33 def active_record_source(scope, id:, geometry:, batch_size: 1_000) require_relative "active_record_source" source do TG::Geometry::ActiveRecordSource.call( scope, id: id, geometry: geometry, batch_size: batch_size ) end end |
.index_options(**options) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/tg/geometry/registry.rb', line 24 def (**) if .empty? inherited = superclass.respond_to?(:index_options) ? superclass. : DEFAULT_INDEX_OPTIONS inherited.merge(@index_options || {}).freeze else @index_options = .merge().freeze end end |
.source(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/tg/geometry/registry.rb', line 14 def source(&block) if block @source = block elsif instance_variable_defined?(:@source) @source elsif superclass.respond_to?(:source) superclass.source end end |
Instance Method Details
#bbox ⇒ Object
79 80 81 |
# File 'lib/tg/geometry/registry.rb', line 79 def bbox current_index.bbox end |
#covering_ids(lon, lat) ⇒ Object
87 88 89 |
# File 'lib/tg/geometry/registry.rb', line 87 def covering_ids(lon, lat) current_index.covering_ids(lon, lat) end |
#covering_ids_batch_packed(binary_string) ⇒ Object
95 96 97 |
# File 'lib/tg/geometry/registry.rb', line 95 def covering_ids_batch_packed(binary_string) current_index.covering_ids_batch_packed(binary_string) end |
#find_covering(lon, lat) ⇒ Object
83 84 85 |
# File 'lib/tg/geometry/registry.rb', line 83 def find_covering(lon, lat) current_index.find_covering(lon, lat) end |
#index ⇒ Object
67 68 69 |
# File 'lib/tg/geometry/registry.rb', line 67 def index @index || raise(TG::Geometry::Error, "registry index is not loaded; call reload! first") end |
#intersecting_rect(min_x, min_y, max_x, max_y) ⇒ Object
91 92 93 |
# File 'lib/tg/geometry/registry.rb', line 91 def intersecting_rect(min_x, min_y, max_x, max_y) current_index.intersecting_rect(min_x, min_y, max_x, max_y) end |
#loaded? ⇒ Boolean
71 72 73 |
# File 'lib/tg/geometry/registry.rb', line 71 def loaded? !@index.nil? end |
#reload! ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/tg/geometry/registry.rb', line 57 def reload! new_index = TG::Geometry::Index.build(resolve_entries, **@index_options) @reload_mutex.synchronize do @index = new_index end new_index end |
#size ⇒ Object
75 76 77 |
# File 'lib/tg/geometry/registry.rb', line 75 def size current_index.size end |