Module: SpatialFeatures::InstanceMethods
- Defined in:
- lib/spatial_features/has_spatial_features.rb
Instance Method Summary collapse
- #acts_like_spatial_features? ⇒ 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?(other, buffer_in_meters) ⇒ Boolean
- #total_intersection_area_in_square_meters(other) ⇒ Object
- #total_intersection_area_percentage(klass) ⇒ Object
Instance Method Details
#acts_like_spatial_features? ⇒ Boolean
163 164 165 |
# File 'lib/spatial_features/has_spatial_features.rb', line 163 def acts_like_spatial_features? true end |
#features? ⇒ Boolean
183 184 185 |
# File 'lib/spatial_features/has_spatial_features.rb', line 183 def features? features.present? end |
#features_area_in_square_meters ⇒ Object
197 198 199 |
# File 'lib/spatial_features/has_spatial_features.rb', line 197 def features_area_in_square_meters @features_area_in_square_meters ||= features.area end |
#features_cache_key ⇒ Object
167 168 169 |
# File 'lib/spatial_features/has_spatial_features.rb', line 167 def features_cache_key "#{self.class.name}/#{self.id}-#{features.cache_key}" end |
#intersects?(other) ⇒ Boolean
187 188 189 |
# File 'lib/spatial_features/has_spatial_features.rb', line 187 def intersects?(other) self.class.intersecting(other).exists?(self) end |
#lines? ⇒ Boolean
175 176 177 |
# File 'lib/spatial_features/has_spatial_features.rb', line 175 def lines? !features.lines.empty? end |
#points? ⇒ Boolean
179 180 181 |
# File 'lib/spatial_features/has_spatial_features.rb', line 179 def points? !features.points.empty? end |
#polygons? ⇒ Boolean
171 172 173 |
# File 'lib/spatial_features/has_spatial_features.rb', line 171 def polygons? !features.polygons.empty? end |
#spatial_cache_for?(other, buffer_in_meters) ⇒ Boolean
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/spatial_features/has_spatial_features.rb', line 207 def spatial_cache_for?(other, buffer_in_meters) if cache = spatial_caches.between(self, SpatialFeatures::Utils.class_of(other)).first 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
201 202 203 204 205 |
# File 'lib/spatial_features/has_spatial_features.rb', line 201 def total_intersection_area_in_square_meters(other) other = other.intersecting(self) unless other.is_a?(ActiveRecord::Base) return features.area if spatial_cache_for?(other, 0) && SpatialProximity.between(self, other).where('intersection_area_in_square_meters >= ?', features.area).exists? return features.total_intersection_area_in_square_meters(other.features) end |
#total_intersection_area_percentage(klass) ⇒ Object
191 192 193 194 195 |
# File 'lib/spatial_features/has_spatial_features.rb', line 191 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 |