Module: SpatialFeatures::ClassMethods
- Defined in:
- lib/spatial_features/has_spatial_features.rb
Instance Method Summary collapse
- #acts_like_spatial_features? ⇒ Boolean
- #aggregate_features ⇒ Object
- #area_in_square_meters ⇒ Object
- #features ⇒ Object
- #features_cache_key ⇒ Object
-
#has_features_area? ⇒ Boolean
Returns true if the model stores a cache of the features area.
-
#has_spatial_features_hash? ⇒ Boolean
Returns true if the model stores a hash of the features so we don’t need to process the features if they haven’t changed.
- #intersecting(other, options = {}) ⇒ Object
- #lines ⇒ Object
- #points ⇒ Object
- #polygons ⇒ Object
- #within_buffer(other, buffer_in_meters = 0, options = {}) ⇒ Object
Instance Method Details
#acts_like_spatial_features? ⇒ Boolean
35 36 37 |
# File 'lib/spatial_features/has_spatial_features.rb', line 35 def acts_like_spatial_features? true end |
#aggregate_features ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/spatial_features/has_spatial_features.rb', line 80 def aggregate_features type = base_class.to_s # Rails stores polymorphic foreign keys as the base class if all == unscoped AggregateFeature.where(:spatial_model_type => type) else AggregateFeature.where(:spatial_model_type => type, :spatial_model_id => all.unscope(:select)) end end |
#area_in_square_meters ⇒ Object
99 100 101 |
# File 'lib/spatial_features/has_spatial_features.rb', line 99 def area_in_square_meters features.area end |
#features ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/spatial_features/has_spatial_features.rb', line 71 def features type = base_class.to_s # Rails stores polymorphic foreign keys as the base class if all == unscoped Feature.where(:spatial_model_type => type) else Feature.where(:spatial_model_type => type, :spatial_model_id => all.unscope(:select)) end end |
#features_cache_key ⇒ Object
39 40 41 |
# File 'lib/spatial_features/has_spatial_features.rb', line 39 def features_cache_key "#{name}/#{aggregate_features.cache_key}" end |
#has_features_area? ⇒ Boolean
Returns true if the model stores a cache of the features area
95 96 97 |
# File 'lib/spatial_features/has_spatial_features.rb', line 95 def has_features_area? owner_class_has_loaded_column?('features_area') end |
#has_spatial_features_hash? ⇒ Boolean
Returns true if the model stores a hash of the features so we don’t need to process the features if they haven’t changed
90 91 92 |
# File 'lib/spatial_features/has_spatial_features.rb', line 90 def has_spatial_features_hash? owner_class_has_loaded_column?('features_hash') end |
#intersecting(other, options = {}) ⇒ Object
43 44 45 |
# File 'lib/spatial_features/has_spatial_features.rb', line 43 def intersecting(other, = {}) within_buffer(other, 0, ) end |
#lines ⇒ Object
63 64 65 |
# File 'lib/spatial_features/has_spatial_features.rb', line 63 def lines features.lines end |
#points ⇒ Object
67 68 69 |
# File 'lib/spatial_features/has_spatial_features.rb', line 67 def points features.points end |
#polygons ⇒ Object
59 60 61 |
# File 'lib/spatial_features/has_spatial_features.rb', line 59 def polygons features.polygons end |
#within_buffer(other, buffer_in_meters = 0, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spatial_features/has_spatial_features.rb', line 47 def within_buffer(other, buffer_in_meters = 0, = {}) return none if other.is_a?(ActiveRecord::Base) && other.new_record? # Cache only works on single records, not scopes. # This is because the cached intersection_area doesn't account for overlaps between the features in the scope. if [:cache] != false && other.is_a?(ActiveRecord::Base) cached_within_buffer_scope(other, buffer_in_meters, ) else uncached_within_buffer_scope(other, buffer_in_meters, ) end end |