spatial_features 2.15.0 → 2.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/abstract_feature.rb +16 -10
- data/lib/spatial_features/has_spatial_features.rb +14 -0
- 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: b61f238cf2d0fa0dd936d9258c617708ea7e4e4ec4be41257b0a3869cde54d4d
|
4
|
+
data.tar.gz: 5ea8025d332dd1fedeab4a90c878568567710d139eba76547cf695e0bbedfd66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8089ccc6e35bf54547f72d11332d3112388ba86ba2dd4828080f7be12a075ab3f33c3d181d79dd7c4403bfd7d9c2e8d6ff7842d57dcfc6ad2a775361d1ce5844
|
7
|
+
data.tar.gz: 6ae887ec028239d8d0431ecdbf2006f0f5b7a8ecf04e3c1b45adadd5a080a44b2b447787e178614610f1627a5cfe244cfee2fabd9670fa617deb516a87813512
|
@@ -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,10 +122,17 @@ class AbstractFeature < ActiveRecord::Base
|
|
123
122
|
SQL
|
124
123
|
end
|
125
124
|
|
126
|
-
def self.geojson(lowres: false, precision: 6, properties:
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
+
|
134
|
+
properties_sql = <<~SQL if properties
|
135
|
+
, 'properties', hstore_to_json(metadata)
|
130
136
|
SQL
|
131
137
|
|
132
138
|
sql = <<~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
|
|
@@ -228,6 +237,11 @@ module SpatialFeatures
|
|
228
237
|
return false
|
229
238
|
end
|
230
239
|
end
|
240
|
+
|
241
|
+
# 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
|
242
|
+
def aggregate_features
|
243
|
+
self.class.where(id: id).aggregate_features
|
244
|
+
end
|
231
245
|
end
|
232
246
|
|
233
247
|
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.1
|
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-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|