Class: Feature
- Inherits:
-
AbstractFeature
- Object
- ActiveRecord::Base
- AbstractFeature
- Feature
- Defined in:
- app/models/feature.rb
Constant Summary
Constants inherited from AbstractFeature
AbstractFeature::FEATURE_TYPES
Instance Attribute Summary collapse
-
#importable_image_paths ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.cache_derivatives(options = {}) ⇒ Object
Features are used for display so we also cache their KML representation.
- .defer_aggregate_refresh(&block) ⇒ Object
- .refresh_aggregates ⇒ Object
- .without_aggregate_refresh ⇒ Object
Instance Method Summary collapse
Methods inherited from AbstractFeature
area_in_square_meters, #cache_derivatives, cache_key, collection_cache_key, #envelope, #feature_bounds, #geojson, geojson, intersecting, invalid, #kml, lines, #make_valid?, points, polygons, total_intersection_area_in_square_meters, valid, with_metadata, within_distance, within_distance_of_point, without_caching_derivatives
Instance Attribute Details
#importable_image_paths ⇒ Object
:nodoc:
18 19 20 |
# File 'app/models/feature.rb', line 18 def importable_image_paths @importable_image_paths end |
Class Method Details
.cache_derivatives(options = {}) ⇒ Object
Features are used for display so we also cache their KML representation
21 22 23 24 25 26 27 28 |
# File 'app/models/feature.rb', line 21 def self.cache_derivatives( = {}) super update_all <<-SQL.squish kml = ST_AsKML(geog, 6), kml_lowres = ST_AsKML(geom_lowres, #{.fetch(:lowres_precision, lowres_precision)}), kml_centroid = ST_AsKML(centroid) SQL end |
.defer_aggregate_refresh(&block) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/feature.rb', line 30 def self.defer_aggregate_refresh(&block) start_at = Feature.maximum(:id).to_i + 1 output = without_aggregate_refresh(&block) where(:id => start_at..Float::INFINITY).refresh_aggregates return output end |
.refresh_aggregates ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/feature.rb', line 47 def self.refresh_aggregates # Find one feature from each spatial model and trigger the aggregate feature refresh ids = where.not(:spatial_model_type => nil) .where.not(:spatial_model_id => nil) .group('spatial_model_type, spatial_model_id') .pluck('MAX(id)') # Unscope so that newly built AggregateFeatures get their type column set correctly AbstractFeature.unscoped { where(:id => ids).find_each(&:refresh_aggregate) } end |
Instance Method Details
#automatically_refresh_aggregate? ⇒ Boolean
63 64 65 66 67 68 |
# File 'app/models/feature.rb', line 63 def automatically_refresh_aggregate? # Check if there is a spatial model id because nothing prevents is from creating a Feature without one. Depending on # how you assign a feature to a record, you may end up saving it before assigning it to a record, thereby leaving # this field blank. spatial_model_id? && automatically_refresh_aggregate && saved_change_to_geog? end |
#refresh_aggregate ⇒ Object
58 59 60 61 |
# File 'app/models/feature.rb', line 58 def refresh_aggregate aggregate_feature&.destroy # Destroy the existing aggregate feature to ensure its cache key changes when it is refreshed create_aggregate_feature! end |