Class: AggregateFeature

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

Constant Summary

Constants inherited from AbstractFeature

AbstractFeature::FEATURE_TYPES

Instance Method Summary collapse

Methods inherited from AbstractFeature

area_in_square_meters, #cache_derivatives, 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, without_caching_derivatives

Instance Method Details

#refreshObject

Aggregate the features for the spatial model into a single feature



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/aggregate_feature.rb', line 7

def refresh
  feature_array_sql = "    ARRAY[\n      (\#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 1))').to_sql}),\n      (\#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 2))').to_sql}),\n      (\#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 3))').to_sql})\n    ]\n  SQL\n\n  # Remove empty features so ST_COLLECT doesn't choke. This seems to be a difference between PostGIS 2.x and 3.x\n  self.geog = SpatialFeatures::Utils.select_db_value <<~SQL\n    SELECT COALESCE(ST_Collect(unnest)::geography, ST_GeogFromText('MULTIPOLYGON EMPTY'))\n    FROM (SELECT unnest(\#{feature_array_sql})) AS features\n    WHERE NOT ST_IsEmpty(unnest)\n  SQL\n  self.save!\nend\n"