Module: SpatialFeatures::InstanceMethods
- Defined in:
- lib/spatial_features/has_spatial_features.rb
Instance Method Summary collapse
- #acts_like_spatial_features? ⇒ Boolean
- #covers?(other) ⇒ Boolean
- #features? ⇒ Boolean
- #features_area_in_square_meters ⇒ Object
- #features_cache_key ⇒ Object
- #intersects?(other) ⇒ Boolean
- #lines? ⇒ Boolean
- #points? ⇒ Boolean
- #polygons? ⇒ Boolean
- #spatial_cache_for(klass) ⇒ Object
- #spatial_cache_for?(klass, buffer_in_meters) ⇒ Boolean
- #total_intersection_area_in_square_meters(other) ⇒ Object
- #total_intersection_area_percentage(klass) ⇒ Object
- #update_features_area ⇒ Object
Instance Method Details
#acts_like_spatial_features? ⇒ Boolean
179 180 181 |
# File 'lib/spatial_features/has_spatial_features.rb', line 179 def acts_like_spatial_features? true end |
#covers?(other) ⇒ Boolean
204 205 206 |
# File 'lib/spatial_features/has_spatial_features.rb', line 204 def covers?(other) self.class.covering(other).exists?(self) end |
#features? ⇒ Boolean
200 201 202 |
# File 'lib/spatial_features/has_spatial_features.rb', line 200 def features? features.present? end |
#features_area_in_square_meters ⇒ Object
218 219 220 |
# File 'lib/spatial_features/has_spatial_features.rb', line 218 def features_area_in_square_meters @features_area_in_square_meters ||= features.area end |
#features_cache_key ⇒ Object
183 184 185 186 |
# File 'lib/spatial_features/has_spatial_features.rb', line 183 def features_cache_key max_id, count = features.pluck("MAX(id), COUNT(*)").first "#{self.class.name}/#{self.id}-#{max_id}-#{count}" end |
#intersects?(other) ⇒ Boolean
208 209 210 |
# File 'lib/spatial_features/has_spatial_features.rb', line 208 def intersects?(other) self.class.intersecting(other).exists?(self) end |
#lines? ⇒ Boolean
192 193 194 |
# File 'lib/spatial_features/has_spatial_features.rb', line 192 def lines? !features.lines.empty? end |
#points? ⇒ Boolean
196 197 198 |
# File 'lib/spatial_features/has_spatial_features.rb', line 196 def points? !features.points.empty? end |
#polygons? ⇒ Boolean
188 189 190 |
# File 'lib/spatial_features/has_spatial_features.rb', line 188 def polygons? !features.polygons.empty? end |
#spatial_cache_for(klass) ⇒ Object
239 240 241 |
# File 'lib/spatial_features/has_spatial_features.rb', line 239 def spatial_cache_for(klass) spatial_cache.where(:intersection_model_type => klass).first end |
#spatial_cache_for?(klass, buffer_in_meters) ⇒ Boolean
227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/spatial_features/has_spatial_features.rb', line 227 def spatial_cache_for?(klass, buffer_in_meters) if cache = spatial_cache_for(klass) return cache.intersection_cache_distance.nil? if buffer_in_meters.nil? # cache must be total if no buffer_in_meters return false if cache.stale? # cache must be for current features return true if cache.intersection_cache_distance.nil? # always good if cache is total return buffer_in_meters <= cache.intersection_cache_distance else return false end end |
#total_intersection_area_in_square_meters(other) ⇒ Object
222 223 224 225 |
# File 'lib/spatial_features/has_spatial_features.rb', line 222 def total_intersection_area_in_square_meters(other) other = other.intersecting(self) unless other.is_a?(ActiveRecord::Base) return features.total_intersection_area_in_square_meters(other.features) end |
#total_intersection_area_percentage(klass) ⇒ Object
212 213 214 215 216 |
# File 'lib/spatial_features/has_spatial_features.rb', line 212 def total_intersection_area_percentage(klass) return 0.0 unless features_area_in_square_meters > 0 ((total_intersection_area_in_square_meters(klass) / features_area_in_square_meters) * 100).round(1) end |
#update_features_area ⇒ Object
243 244 245 |
# File 'lib/spatial_features/has_spatial_features.rb', line 243 def update_features_area update_column :features_area, features.area(:cache => false) end |