Class: Feature
Constant Summary
AbstractFeature::FEATURE_TYPES
Class Method Summary
collapse
Instance Method Summary
collapse
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
Class Method Details
.cache_derivatives(options = {}) ⇒ Object
Features are used for display so we also cache their KML representation
19
20
21
22
23
24
25
26
|
# File 'app/models/feature.rb', line 19
def self.cache_derivatives(options = {})
super
update_all " kml = ST_AsKML(geog, 6),\n kml_lowres = ST_AsKML(geom_lowres, \#{options.fetch(:lowres_precision, lowres_precision)}),\n kml_centroid = ST_AsKML(centroid)\n SQL\nend\n".squish
|
.defer_aggregate_refresh(&block) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'app/models/feature.rb', line 28
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
45
46
47
48
49
50
51
52
53
54
|
# File 'app/models/feature.rb', line 45
def self.refresh_aggregates
ids = where.not(:spatial_model_type => nil)
.where.not(:spatial_model_id => nil)
.group('spatial_model_type, spatial_model_id')
.pluck('MAX(id)')
AbstractFeature.unscoped { where(:id => ids).find_each(&:refresh_aggregate) }
end
|
.without_aggregate_refresh ⇒ Object
37
38
39
40
41
42
43
|
# File 'app/models/feature.rb', line 37
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
61
62
63
64
65
66
|
# File 'app/models/feature.rb', line 61
def automatically_refresh_aggregate?
spatial_model_id? && automatically_refresh_aggregate && saved_change_to_geog?
end
|
#refresh_aggregate ⇒ Object
56
57
58
59
|
# File 'app/models/feature.rb', line 56
def refresh_aggregate
aggregate_feature&.destroy
create_aggregate_feature!
end
|