spatial_features 1.5.11 → 1.5.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1f2c3d038baab7cfb9b0e8da43f9df18516425a
4
- data.tar.gz: 6f659cee10eb6583fc25d91aa412b0e9fbd94785
3
+ metadata.gz: 73e929f19dbe88a8a660db9905520f65298ae749
4
+ data.tar.gz: ea15f17e06a0c28e3737acde7d102a8111e9624f
5
5
  SHA512:
6
- metadata.gz: 0001489c898f5f27c508c9c46bda80a685914ad34f3d63c7da9e2c98e12fe40dc00eac46b2eab9e942cd48587bc5eff696298cea1f74efc7a6dfad81010d1377
7
- data.tar.gz: 78d28037a3c5e3f1edffc8589b72afb0dd356e7e9cc96a0cd38289a8141cb48045eaf1449d5957c336dbc8f14f6bb935593fd36f8c4fcea11162840fd47f8179
6
+ metadata.gz: 0bfdb3c23c67fd37602798cd56702d87ffb74bb56f1f56066620cec18d40be2e350f761e9442b4007faa3c79df4f09836857f4fa446ef27ed0ce9c0232a9de17
7
+ data.tar.gz: 8531be35e8009f784944d55d979c7450304141736d6f0805dbb21c844452da039b883177a9bd539aac47ff9ca814b6eb2f7ccc32fd263270798e286f448768f1
@@ -33,11 +33,16 @@ class Feature < ActiveRecord::Base
33
33
  end
34
34
 
35
35
  def self.total_intersection_area_in_square_meters(other)
36
- scope = join_other_features(other)
37
- .where('ST_Intersects(features.geog_lowres, other_features.geog_lowres)')
38
- .select('ST_Area(ST_Intersection(ST_Union(features.geog_lowres::geometry), ST_Union(other_features.geog_lowres::geometry))::geography) AS intersection_area_in_square_meters')
36
+ other_features = unscoped.flattened_features.where(:id => intersecting(other).select('other_features.id'))
39
37
 
40
- connection.select_value(scope).to_f
38
+ unscoped
39
+ .from("(#{flattened_features.to_sql}) features, (#{other_features.to_sql}) other_features")
40
+ .pluck('ST_Area(ST_Intersection(features.geom, other_features.geom))')
41
+ .first.to_f
42
+ end
43
+
44
+ def self.intersecting(other)
45
+ join_other_features(other).where('ST_Intersects(features.geog_lowres, other_features.geog_lowres)').uniq
41
46
  end
42
47
 
43
48
  def self.invalid
@@ -87,6 +92,10 @@ class Feature < ActiveRecord::Base
87
92
 
88
93
  private
89
94
 
95
+ def self.flattened_features
96
+ select('ST_Union(features.geom) AS geom')
97
+ end
98
+
90
99
  def self.detect_srid(column_name)
91
100
  connection.select_value("SELECT Find_SRID('public', '#{table_name}', '#{column_name}')")
92
101
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "1.5.11"
2
+ VERSION = "1.5.12"
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: 1.5.11
4
+ version: 1.5.12
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: 2016-07-27 00:00:00.000000000 Z
12
+ date: 2016-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails