spatial_features 2.15.0 → 2.17.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79fb559903943c11893b5d338f5c8030971f23051cf3611a326d0e013720f5e5
4
- data.tar.gz: 1311241026ec5dc76a90e04f8fcc9e93c92965875f0967e1b27a0e1f64694ab3
3
+ metadata.gz: b61f238cf2d0fa0dd936d9258c617708ea7e4e4ec4be41257b0a3869cde54d4d
4
+ data.tar.gz: 5ea8025d332dd1fedeab4a90c878568567710d139eba76547cf695e0bbedfd66
5
5
  SHA512:
6
- metadata.gz: 8080e32e08c262fb3c44c6a228b0c599a1030ec52f9daea7862a06a98aa72b46dad77fb73127d5d40e6e999549ea44ebde0b77e826b1776e92eefe6b4a14898c
7
- data.tar.gz: 3d591754fdc5a1ddb92146d805074aa5dc4bc65f5261eb0c169546f886b5dee784de7f24f56829a359641ae778960ffd54923c6b2535261d2e1194e0c9db0859
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: {}, srid: 4326) # default srid is 4326 so output is Google Maps compatible
127
- column = lowres ? "ST_Transform(geom_lowres, #{srid})" : 'geog'
128
- properties_sql = <<~SQL if properties.present?
129
- , 'properties', json_build_object(#{properties.map {|k,v| "'#{k}',#{v}" }.join(',') })
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
- {n: north, e: east, s: south, w: west}
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
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.15.0"
2
+ VERSION = "2.17.1"
3
3
  end
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.15.0
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-07-06 00:00:00.000000000 Z
12
+ date: 2021-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails