spatial_features 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spatial_features.rb +2 -0
- data/lib/spatial_features/controller_helpers/spatial_extensions.rb +18 -0
- data/lib/spatial_features/import/arcgis_kmz_features.rb +8 -0
- data/lib/spatial_features/venn_polygons.rb +1 -1
- data/lib/spatial_features/version.rb +1 -1
- data/lib/spatial_features/workers/arcgis_update_features_job.rb +39 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53382056faffc16249a7d7787da478f0c5304642
|
4
|
+
data.tar.gz: b28b4a4c8048dc8e25714bd3e8b9a05c6b148962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d53442af20766b25679809a8f0ceddad23ec8f2ca97362392b4002cfd6653f4be70aea30e97314be84a863268b28c622bd33af3d326e7c655c402c0e12f182
|
7
|
+
data.tar.gz: bde880afe16008e1060563432b73daf032af42d6c4bca901435f81fc0e430eecc9ff0023ebc07db214ab12dc695a9407edf1df73476e26f807dac13ae13beb3c
|
data/lib/spatial_features.rb
CHANGED
@@ -11,6 +11,8 @@ require 'spatial_features/models/feature'
|
|
11
11
|
require 'spatial_features/models/spatial_cache'
|
12
12
|
require 'spatial_features/models/spatial_proximity'
|
13
13
|
|
14
|
+
require 'spatial_features/workers/arcgis_update_features_job'
|
15
|
+
|
14
16
|
require 'spatial_features/engine'
|
15
17
|
|
16
18
|
module SpatialFeatures
|
@@ -1,6 +1,24 @@
|
|
1
1
|
module SpatialExtensions
|
2
2
|
private
|
3
3
|
|
4
|
+
def abstract_refresh_geometry_action(model, cache_classes)
|
5
|
+
queue = "#{model.class}/#{model.id}/update_features"
|
6
|
+
|
7
|
+
# Destroy old failed jobs
|
8
|
+
Delayed::Job.where(:queue => queue).where.not(:failed_at => nil).destroy_all
|
9
|
+
|
10
|
+
Delayed::Job.enqueue(
|
11
|
+
ArcGISUpdateFeaturesJob.new(
|
12
|
+
:spatial_model_type => model.class,
|
13
|
+
:spatial_model_id => model.id,
|
14
|
+
:cache_classes => cache_classes
|
15
|
+
),
|
16
|
+
:queue => queue
|
17
|
+
)
|
18
|
+
|
19
|
+
redirect_to :back
|
20
|
+
end
|
21
|
+
|
4
22
|
def abstract_proximity_action(scope, target, distance, &block)
|
5
23
|
@nearby_records = scope_for_search(scope).within_buffer(target, distance, :distance => true, :intersection_area => true).order('distance_in_meters ASC, intersection_area_in_square_meters DESC, id ASC')
|
6
24
|
@target = target
|
@@ -28,6 +28,14 @@ module ArcGISKmzFeatures
|
|
28
28
|
return true
|
29
29
|
end
|
30
30
|
|
31
|
+
def updating_features?
|
32
|
+
Delayed::Job.where(queue: "#{self.class}/#{self.id}/update_features", failed_at: nil).exists?
|
33
|
+
end
|
34
|
+
|
35
|
+
def feature_update_error
|
36
|
+
(Delayed::Job.where(queue: "#{self.class}/#{self.id}/update_features").where.not(failed_at: nil).first.try(:last_error) || '').split("\n").first
|
37
|
+
end
|
38
|
+
|
31
39
|
private
|
32
40
|
|
33
41
|
def replace_features(kml_array)
|
@@ -29,7 +29,7 @@ module SpatialFeatures
|
|
29
29
|
if options[:target]
|
30
30
|
sql <<
|
31
31
|
"INNER JOIN features
|
32
|
-
ON features.spatial_model_type = '#{options[:target].class}' AND features.spatial_model_id = #{options[:target].id} AND ST_Intersects(features.geom, venn_polygons.geom)"
|
32
|
+
ON features.spatial_model_type = '#{options[:target].class}' AND features.spatial_model_id = #{options[:target].id} AND ST_Intersects(features.geom, venn_polygons.geom) "
|
33
33
|
end
|
34
34
|
|
35
35
|
# Join with the original polygons so we can determine which original polygons each venn polygon came from
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ArcGISUpdateFeaturesJob < Struct.new(:options)
|
2
|
+
def perform
|
3
|
+
model = options[:spatial_model_type].find(options[:spatial_model_id])
|
4
|
+
|
5
|
+
if model.update_features!
|
6
|
+
options[:cache_classes].each {|klass| SpatialFeatures.cache_record_proximity(model, klass) }
|
7
|
+
end
|
8
|
+
rescue => e
|
9
|
+
raise "Can't refresh geometry: #{normalize_message(e.message)}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def normalize_message(message)
|
15
|
+
if message =~ /\Agetaddrinfo/
|
16
|
+
"ArcGIS Server is not responding."
|
17
|
+
elsif message =~ /invalid KML representation/
|
18
|
+
invalid_kml_reason(message) || "invalid KML being generated by ArcGIS."
|
19
|
+
elsif message =~ /Self-intersection/
|
20
|
+
message.scan(/\[(\d+(?:\.\d+)?) (\d+(?:\.\d+)?)\]/).each do |lng, lat|
|
21
|
+
"Self-intersection at #{lng},#{lat}"
|
22
|
+
end.join(', ')
|
23
|
+
else
|
24
|
+
message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
NUMBER_REGEX = /-?\d+\.\d+/
|
29
|
+
COORDINATE_REGEX = /<LinearRing><coordinates>\s*((?:#{NUMBER_REGEX},#{NUMBER_REGEX},#{NUMBER_REGEX}\s*)+)<\/coordinates><\/LinearRing>/
|
30
|
+
def invalid_kml_reason(message)
|
31
|
+
message.scan(COORDINATE_REGEX) do |match|
|
32
|
+
coords = match[0].split(/(?:,0\.0+)?\s+/).chunk {|c| c }.map(&:first)
|
33
|
+
|
34
|
+
return "KML ring doesn't have enough points #{coords.first}" if coords.length < 4
|
35
|
+
end
|
36
|
+
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
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.0
|
4
|
+
version: 1.1.0
|
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: 2015-01-
|
12
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: delayed_job_active_record
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: pg
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +75,7 @@ files:
|
|
61
75
|
- lib/spatial_features/models/spatial_proximity.rb
|
62
76
|
- lib/spatial_features/venn_polygons.rb
|
63
77
|
- lib/spatial_features/version.rb
|
78
|
+
- lib/spatial_features/workers/arcgis_update_features_job.rb
|
64
79
|
- lib/tasks/spatial_features_tasks.rake
|
65
80
|
- test/dummy/README.rdoc
|
66
81
|
- test/dummy/Rakefile
|
@@ -117,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
132
|
version: '0'
|
118
133
|
requirements: []
|
119
134
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.4.5
|
121
136
|
signing_key:
|
122
137
|
specification_version: 4
|
123
138
|
summary: Adds spatial methods to a model.
|