Class: Feature

Inherits:
AbstractFeature show all
Defined in:
app/models/feature.rb

Constant Summary

Constants inherited from AbstractFeature

AbstractFeature::FEATURE_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractFeature

area_in_square_meters, bounds, #bounds, cache_derivatives, #cache_derivatives, cache_key, collection_cache_key, #envelope, geojson, #geojson, intersecting, invalid, #kml, lines, #make_valid?, metadata_keys, mvt, mvt_sql, points, polygons, total_intersection_area_in_square_meters, valid, with_metadata, within_distance, within_distance_of_line, within_distance_of_point, within_distance_of_polygon, within_distance_of_sql, without_caching_derivatives

Instance Attribute Details

#importable_image_pathsObject

:nodoc:



18
19
20
# File 'app/models/feature.rb', line 18

def importable_image_paths
  @importable_image_paths
end

Class Method Details

.defer_aggregate_refresh(&block) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/models/feature.rb', line 20

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_aggregatesObject



37
38
39
40
41
42
43
44
45
46
# File 'app/models/feature.rb', line 37

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

.without_aggregate_refreshObject



29
30
31
32
33
34
35
# File 'app/models/feature.rb', line 29

def self.without_aggregate_refresh
  old = Feature.automatically_refresh_aggregate
  Feature.automatically_refresh_aggregate = false
  yield
ensure
  Feature.automatically_refresh_aggregate = old
end

Instance Method Details

#automatically_refresh_aggregate?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'app/models/feature.rb', line 53

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_aggregateObject



48
49
50
51
# File 'app/models/feature.rb', line 48

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