spatial_features 2.10.9 → 2.12.2
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 +7 -1
- data/config/initializers/register_oids.rb +3 -3
- data/lib/spatial_features/has_spatial_features.rb +11 -6
- data/lib/spatial_features/has_spatial_features/feature_import.rb +4 -3
- data/lib/spatial_features/importers/kml.rb +13 -11
- data/lib/spatial_features/version.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0051ead788fe05361e242dd7043efe1dee46c31260f4b3fdc782c06af5238e73
|
4
|
+
data.tar.gz: f9658375cee39987dd047839222781eb12b35eab73eb950e62c4349e47955dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2738a619531511cf2d90052a6ffdab481b5edfc875271cae30df287759ccdc09dcb1df8291c63192e5e618291410befd2d5cfcd3a3155f852a5d59c44b5b6aff
|
7
|
+
data.tar.gz: 114543074b9bdfea813e979505829d6282ec49524fe9ad4093b1119e7099feec2205f8b5a33b447ca8cac05470ae74b12ee93b9a7a3c6f7e66d9497ce43fa2ca
|
@@ -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
|
-
|
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)
|
@@ -40,6 +41,11 @@ class AbstractFeature < ActiveRecord::Base
|
|
40
41
|
where(:feature_type => 'point')
|
41
42
|
end
|
42
43
|
|
44
|
+
def self.within_distance(lat, lng, distance_in_meters)
|
45
|
+
# where("ST_DWithin(features.geog, ST_SetSRID( ST_Point( -71.104, 42.315), 4326)::geography, :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
|
46
|
+
where("ST_DWithin(features.geog, ST_Point(:lng, :lat), :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
|
47
|
+
end
|
48
|
+
|
43
49
|
def self.area_in_square_meters(geom = 'geom_lowres')
|
44
50
|
current_scope = all.polygons
|
45
51
|
unscoped { connection.select_value(select("ST_Area(ST_Union(#{geom}))").from(current_scope, :features)).to_f }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PostGISTypes
|
2
|
-
def initialize_type_map(
|
2
|
+
def initialize_type_map(m = type_map)
|
3
3
|
super
|
4
|
-
register_class_with_limit
|
5
|
-
register_class_with_limit
|
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
|
-
#
|
44
|
-
"#{name}/#{features.cache_key}"
|
40
|
+
"#{name}/#{aggregate_features.cache_key}"
|
45
41
|
end
|
46
42
|
|
47
43
|
def intersecting(other, options = {})
|
@@ -81,6 +77,15 @@ module SpatialFeatures
|
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
80
|
+
def aggregate_features
|
81
|
+
type = base_class.to_s # Rails stores polymorphic foreign keys as the base class
|
82
|
+
if all == unscoped
|
83
|
+
AggregateFeature.where(:spatial_model_type => type)
|
84
|
+
else
|
85
|
+
AggregateFeature.where(:spatial_model_type => type, :spatial_model_id => all.unscope(:select))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
84
89
|
# Returns true if the model stores a hash of the features so we don't need to process the features if they haven't changed
|
85
90
|
def has_spatial_features_hash?
|
86
91
|
column_names.include? 'features_hash'
|
@@ -163,7 +168,7 @@ module SpatialFeatures
|
|
163
168
|
end
|
164
169
|
|
165
170
|
def features_cache_key
|
166
|
-
"#{self.class.name}/#{
|
171
|
+
"#{self.class.name}/#{id}-#{has_spatial_features_hash? ? features_hash : aggregate_feature.cache_key}"
|
167
172
|
end
|
168
173
|
|
169
174
|
def polygons?
|
@@ -67,9 +67,10 @@ module SpatialFeatures
|
|
67
67
|
private
|
68
68
|
|
69
69
|
def spatial_feature_imports(import_options, make_valid)
|
70
|
-
import_options.
|
71
|
-
|
72
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
24
|
-
|
25
|
+
def blank_feature?(feature)
|
26
|
+
feature.css('coordinates').text.blank?
|
25
27
|
end
|
26
28
|
|
27
29
|
def geom_from_kml(kml)
|
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.
|
4
|
+
version: 2.12.2
|
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-
|
12
|
+
date: 2020-08-23 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: '
|
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: '
|
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
|
-
|
224
|
-
|
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: []
|