spatial_features 2.11.0 → 2.12.3

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: fb5268adbbf2c9b9019512e4d3617fc97c587497913202bf95c3dd35332497e8
4
- data.tar.gz: 37928531494a21c1934425bb222759accdbfae763c7eb2e7f5570e8e17c69e42
3
+ metadata.gz: a7dc123319b7699b8cdd61e7957ad5be3b173e2c6e80701772293eda72eaa93a
4
+ data.tar.gz: 27d3ed1027be88610afaf8788fb4bc076658f5573bd6337387a0d73ea285a5b1
5
5
  SHA512:
6
- metadata.gz: d995ebde69133a39e99885ce694551d5bd64fb08a67b8e658d86138f56673b78a27f101f65cb86027e864d3fa0a3e2c05f43d944a3c55b2fac1a3e53a304715b
7
- data.tar.gz: 99be0f11815754302e8b3f1cf50fa31964993fa43d2a1cc5a68e688eacb03d0d2116cea1ff71c7c7c8c2c99a7c7ae76c2dc83c0f6bef34ec525434bb990be2e1
6
+ metadata.gz: 6b6d63f7b5a919afeae24b1075bd69a32420cd47b4963a5bcd319d79890c06a284c28b8162e61327ef76c5bbf6acc2f2f8c5c88b82746ebc51c264b24dbe5473
7
+ data.tar.gz: 3eb3585092c0437a1e02881bc52c6f6cffe9d9c7784404b6119db9eb70c4ee46d9d58b614dc3a6496677e1d4a7a203f346340a584b332e6855ad9088a1292a88
@@ -17,7 +17,8 @@ class AbstractFeature < ActiveRecord::Base
17
17
  after_save :cache_derivatives, :if => :saved_change_to_geog?
18
18
 
19
19
  def self.cache_key
20
- "#{maximum(:id)}-#{count}"
20
+ result = connection.select_one(all.select('max(id) AS max, count(*) AS count').to_sql)
21
+ "#{result['max']}-#{result['count']}"
21
22
  end
22
23
 
23
24
  def self.with_metadata(k, v)
@@ -1,8 +1,8 @@
1
1
  module PostGISTypes
2
- def initialize_type_map(mapping)
2
+ def initialize_type_map(m = type_map)
3
3
  super
4
- register_class_with_limit mapping, 'geometry', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
5
- register_class_with_limit mapping, 'geography', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
4
+ register_class_with_limit m, 'geometry', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
5
+ register_class_with_limit m, 'geography', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
6
6
  end
7
7
  end
8
8
 
@@ -36,12 +36,8 @@ module SpatialFeatures
36
36
  true
37
37
  end
38
38
 
39
- # Add methods to generate cache keys for a record or all records of this class
40
- # NOTE: features are never updated, only deleted and created, therefore we can
41
- # tell if they have changed by finding the maximum id and count instead of needing timestamps
42
39
  def features_cache_key
43
- # Do two separate queries because it is much faster for some reason
44
- "#{name}/#{features.cache_key}"
40
+ "#{name}/#{aggregate_features.cache_key}"
45
41
  end
46
42
 
47
43
  def intersecting(other, options = {})
@@ -172,7 +168,7 @@ module SpatialFeatures
172
168
  end
173
169
 
174
170
  def features_cache_key
175
- "#{self.class.name}/#{self.id}-#{features.cache_key}"
171
+ "#{self.class.name}/#{id}-#{has_spatial_features_hash? ? features_hash : aggregate_feature.cache_key}"
176
172
  end
177
173
 
178
174
  def polygons?
@@ -188,7 +184,11 @@ module SpatialFeatures
188
184
  end
189
185
 
190
186
  def features?
191
- features.present?
187
+ if features.loaded?
188
+ features.present?
189
+ else
190
+ features.exists?
191
+ end
192
192
  end
193
193
 
194
194
  def intersects?(other)
@@ -67,9 +67,10 @@ module SpatialFeatures
67
67
  private
68
68
 
69
69
  def spatial_feature_imports(import_options, make_valid)
70
- import_options.collect do |data_method, importer_name|
71
- data = send(data_method)
72
- spatial_importer_from_name(importer_name).new(data, :make_valid => make_valid) if data.present?
70
+ import_options.flat_map do |data_method, importer_name|
71
+ Array.wrap(send(data_method)).map do |data|
72
+ spatial_importer_from_name(importer_name).new(data, :make_valid => make_valid) if data.present?
73
+ end
73
74
  end.compact
74
75
  end
75
76
 
@@ -6,22 +6,24 @@ module SpatialFeatures
6
6
  private
7
7
 
8
8
  def each_record(&block)
9
- Nokogiri::XML(@data).css('Placemark').each do |placemark|
10
- name = placemark.css('name').text
11
- metadata = extract_metadata(placemark)
12
-
13
- {'Polygon' => 'POLYGON', 'LineString' => 'LINE', 'Point' => 'POINT'}.each do |kml_type, sql_type|
14
- placemark.css(kml_type).each do |placemark|
15
- next if blank_placemark?(placemark)
16
-
17
- yield OpenStruct.new(:feature_type => sql_type, :geog => geom_from_kml(placemark), :name => name, :metadata => metadata)
9
+ {'Polygon' => 'POLYGON', 'LineString' => 'LINE', 'Point' => 'POINT'}.each do |kml_type, sql_type|
10
+ Nokogiri::XML(@data).css(kml_type).each do |feature|
11
+ if placemark = feature.ancestors('Placemark').first
12
+ name = placemark.css('name').text
13
+ metadata = extract_metadata(placemark)
14
+ else
15
+ metadata = {}
18
16
  end
17
+
18
+ next if blank_feature?(feature)
19
+
20
+ yield OpenStruct.new(:feature_type => sql_type, :geog => geom_from_kml(feature), :name => name, :metadata => metadata)
19
21
  end
20
22
  end
21
23
  end
22
24
 
23
- def blank_placemark?(placemark)
24
- placemark.css('coordinates').text.blank?
25
+ def blank_feature?(feature)
26
+ feature.css('coordinates').text.blank?
25
27
  end
26
28
 
27
29
  def geom_from_kml(kml)
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.11.0"
2
+ VERSION = "2.12.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_features
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
8
8
  - Nicholas Jakobsen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-01 00:00:00.000000000 Z
12
+ date: 2020-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '4.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.2'
23
+ version: '6.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '4.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '6.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: delayed_job_active_record
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -205,7 +205,7 @@ homepage: https://github.com/culturecode/spatial_features
205
205
  licenses:
206
206
  - MIT
207
207
  metadata: {}
208
- post_install_message:
208
+ post_install_message:
209
209
  rdoc_options: []
210
210
  require_paths:
211
211
  - lib
@@ -220,9 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.7.9
225
- signing_key:
223
+ rubygems_version: 3.0.8
224
+ signing_key:
226
225
  specification_version: 4
227
226
  summary: Adds spatial methods to a model.
228
227
  test_files: []