spatial_features 2.15.1 → 2.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/abstract_feature.rb +14 -8
- data/lib/spatial_features/has_spatial_features.rb +19 -1
- data/lib/spatial_features/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86e67798202370af90674a888afbf1ac4f7847fa24385e1457ebe14e3ff6d4bc
|
4
|
+
data.tar.gz: 75e5c07bb3dc7c3f969f36919d7a468046fec0fcb3683e28f2c862dce9bcee11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc4d1aeb966cc2623bd8d324e6ef1bf1fc8e3b4f4bdffddaf123f30e76d827461b0b2277b141ae57a501fd26dc47105aa289771c70f302d1119f5d7270d9ff96
|
7
|
+
data.tar.gz: 41a82aebeef10ff3445348a0859e2db72f42e4b5041fd27b8b72d1368b12d4294e8ec9b270bcf570280f28b23819ed3ad80b066803c0997eca9777f361a778e2
|
@@ -19,17 +19,16 @@ class AbstractFeature < ActiveRecord::Base
|
|
19
19
|
before_save :sanitize, if: :will_save_change_to_geog?
|
20
20
|
after_save :cache_derivatives, :if => [:automatically_cache_derivatives?, :saved_change_to_geog?]
|
21
21
|
|
22
|
-
def self.cache_key
|
23
|
-
result = connection.select_one(all.select('max(id) AS max, count(*) AS count').to_sql)
|
24
|
-
"#{result['max']}-#{result['count']}"
|
25
|
-
end
|
26
|
-
|
27
22
|
# for Rails >= 5 ActiveRecord collections we override the collection_cache_key
|
28
23
|
# to prevent Rails doing its default query on `updated_at`
|
29
24
|
def self.collection_cache_key(_collection, _timestamp_column)
|
30
25
|
self.cache_key
|
31
26
|
end
|
32
27
|
|
28
|
+
def self.cache_key
|
29
|
+
"#{maximum(:id)}-#{count}"
|
30
|
+
end
|
31
|
+
|
33
32
|
def self.with_metadata(k, v)
|
34
33
|
if k.present? && v.present?
|
35
34
|
where('metadata->? = ?', k, v)
|
@@ -123,8 +122,15 @@ class AbstractFeature < ActiveRecord::Base
|
|
123
122
|
SQL
|
124
123
|
end
|
125
124
|
|
126
|
-
def self.geojson(lowres: false, precision: 6, properties: true, srid: 4326) # default srid is 4326 so output is Google Maps compatible
|
127
|
-
|
125
|
+
def self.geojson(lowres: false, precision: 6, properties: true, srid: 4326, centroids: false) # default srid is 4326 so output is Google Maps compatible
|
126
|
+
if centroids
|
127
|
+
column = 'centroid'
|
128
|
+
elsif lowres
|
129
|
+
column = "ST_Transform(geom_lowres, #{srid})"
|
130
|
+
else
|
131
|
+
column = 'geog'
|
132
|
+
end
|
133
|
+
|
128
134
|
properties_sql = <<~SQL if properties
|
129
135
|
, 'properties', hstore_to_json(metadata)
|
130
136
|
SQL
|
@@ -145,7 +151,7 @@ class AbstractFeature < ActiveRecord::Base
|
|
145
151
|
end
|
146
152
|
|
147
153
|
def feature_bounds
|
148
|
-
|
154
|
+
slice(:north, :east, :south, :west)
|
149
155
|
end
|
150
156
|
|
151
157
|
def cache_derivatives(*args)
|
@@ -201,6 +201,15 @@ module SpatialFeatures
|
|
201
201
|
self.class.unscoped { self.class.intersecting(other).exists?(id) }
|
202
202
|
end
|
203
203
|
|
204
|
+
def bounds
|
205
|
+
if association(:aggregate_feature).loaded?
|
206
|
+
aggregate_feature&.feature_bounds
|
207
|
+
else
|
208
|
+
result = aggregate_features.pluck(:north, :east, :south, :west).first
|
209
|
+
[:north, :east, :south, :west].zip(result.map {|bound| BigDecimal(bound) }).to_h.with_indifferent_access if result
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
204
213
|
def total_intersection_area_percentage(klass)
|
205
214
|
return 0.0 unless features_area_in_square_meters > 0
|
206
215
|
|
@@ -208,7 +217,11 @@ module SpatialFeatures
|
|
208
217
|
end
|
209
218
|
|
210
219
|
def features_area_in_square_meters
|
211
|
-
aggregate_feature
|
220
|
+
if association(:aggregate_feature).loaded?
|
221
|
+
aggregate_feature&.area
|
222
|
+
else
|
223
|
+
aggregate_features.pluck(:area).first
|
224
|
+
end
|
212
225
|
end
|
213
226
|
|
214
227
|
def total_intersection_area_in_square_meters(other)
|
@@ -228,6 +241,11 @@ module SpatialFeatures
|
|
228
241
|
return false
|
229
242
|
end
|
230
243
|
end
|
244
|
+
|
245
|
+
# Scope to perform SQL-only calculations on a record's aggregate feature. This avoids loading the large data payload if all that is needed is metadata
|
246
|
+
def aggregate_features
|
247
|
+
self.class.where(id: id).aggregate_features
|
248
|
+
end
|
231
249
|
end
|
232
250
|
|
233
251
|
module FeaturesAssociationExtensions
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spatial_features
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.17.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Wallace
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|