spatial_features 2.9.0 → 2.9.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3e126c82bcff0ef6828308c9eb5ae062e1540a2fdd817a3be74b85db3b23d19
|
4
|
+
data.tar.gz: cecf17b38121de11392d25196bf788f9da8aa3771401f8d59c295ae7dbdd1140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 686329bb9f5bb6c9e8e7fd8f8d3f64aa63d72f9a892144be8e00239ecf9fc2770b218e9f3c1e6baf7ccd740d6eb96a0798ef4dc4df4a833af503531d08e2df8d
|
7
|
+
data.tar.gz: 6bf976be9ccdb8ed02c6f5802ba93ab730dc6d38b24d98070c4730c1c67bae50c03fd39ac7f2ec2aa05372665adbf8edfc6f04cfc70ad87af25285ab495ab229
|
@@ -5,12 +5,26 @@ class AggregateFeature < AbstractFeature
|
|
5
5
|
|
6
6
|
# Aggregate the features for the spatial model into a single feature
|
7
7
|
def refresh
|
8
|
-
|
9
|
-
|
8
|
+
feature_array_sql = <<~SQL
|
9
|
+
ARRAY[
|
10
10
|
(#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 1))').to_sql}),
|
11
11
|
(#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 2))').to_sql}),
|
12
12
|
(#{features.select('ST_UNION(ST_CollectionExtract(geog::geometry, 3))').to_sql})
|
13
|
-
]
|
13
|
+
]
|
14
|
+
SQL
|
15
|
+
|
16
|
+
# Remove empty features so ST_COLLECT doesn't choke. This seems to be a difference between PostGIS 2.x and 3.x
|
17
|
+
compacted_feature_array_sql = <<~SQL
|
18
|
+
array_remove(
|
19
|
+
array_remove(
|
20
|
+
array_remove(#{feature_array_sql},
|
21
|
+
ST_GeomFromText('Point EMPTY')),
|
22
|
+
ST_GeomFromText('Linestring EMPTY')),
|
23
|
+
ST_GeomFromText('Polygon EMPTY'))
|
24
|
+
SQL
|
25
|
+
|
26
|
+
self.geog = ActiveRecord::Base.connection.select_value <<~SQL
|
27
|
+
SELECT ST_Collect(#{compacted_feature_array_sql})::geography
|
14
28
|
SQL
|
15
29
|
self.save!
|
16
30
|
end
|
@@ -76,19 +76,19 @@ module SpatialFeatures
|
|
76
76
|
def self.create_spatial_proximities(record, klass)
|
77
77
|
klass = klass.to_s.constantize
|
78
78
|
klass_record = klass.new
|
79
|
-
model_a, model_b = Utils.base_class(record).to_s < Utils.base_class(klass).to_s ? [record, klass_record] : [klass_record, record]
|
80
79
|
|
81
80
|
scope = klass.within_buffer(record, default_cache_buffer_in_meters, :columns => :id, :intersection_area => true, :distance => true, :cache => false)
|
81
|
+
scope = scope.where.not(:id => record.id) if klass.table_name == record.class.table_name # Don't calculate self proximity
|
82
82
|
results = klass.connection.select_rows(scope.to_sql)
|
83
83
|
|
84
84
|
results.each do |id, distance, area|
|
85
85
|
klass_record.id = id
|
86
86
|
SpatialProximity.create! do |proximity|
|
87
87
|
# Set id and type instead of model to avoid autosaving the klass_record
|
88
|
-
proximity.model_a_id =
|
89
|
-
proximity.model_a_type = Utils.base_class(
|
90
|
-
proximity.model_b_id =
|
91
|
-
proximity.model_b_type = Utils.base_class(
|
88
|
+
proximity.model_a_id = record.id
|
89
|
+
proximity.model_a_type = Utils.base_class(record)
|
90
|
+
proximity.model_b_id = klass_record.id
|
91
|
+
proximity.model_b_type = Utils.base_class(klass_record)
|
92
92
|
proximity.distance_in_meters = distance
|
93
93
|
proximity.intersection_area_in_square_meters = area
|
94
94
|
end
|
@@ -117,10 +117,11 @@ module SpatialFeatures
|
|
117
117
|
other_class = Utils.base_class_of(other)
|
118
118
|
self_class = Utils.base_class_of(self)
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
joins <<~SQL
|
121
|
+
INNER JOIN spatial_proximities
|
122
|
+
ON (spatial_proximities.model_a_type = '#{self_class}' AND spatial_proximities.model_a_id = #{table_name}.id AND spatial_proximities.model_b_type = '#{other_class}' AND spatial_proximities.model_b_id IN (#{Utils.id_sql(other)}))
|
123
|
+
OR (spatial_proximities.model_b_type = '#{self_class}' AND spatial_proximities.model_b_id = #{table_name}.id AND spatial_proximities.model_a_type = '#{other_class}' AND spatial_proximities.model_a_id IN (#{Utils.id_sql(other)}))
|
124
|
+
SQL
|
124
125
|
end
|
125
126
|
|
126
127
|
def uncached_within_buffer_scope(other, buffer_in_meters, options)
|
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.9.
|
4
|
+
version: 2.9.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: 2019-12-
|
12
|
+
date: 2019-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|