spatial_features 3.6.3 → 3.8.0

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: 90e1672d25b0ffc7f11092c8518322c41597c2ebc826c5db42ab4e20bb5e3ff8
4
- data.tar.gz: 61e0e85d335afd245d87e7d6aef3ad892398c704235b450ab45f949fd7d04a74
3
+ metadata.gz: 54f447bf36298072b9480e0f33faa93145d8f4dbdecd5d1422001f0202a25354
4
+ data.tar.gz: 2546213005b5fde86ed5732c9d408a9b1ee7f30d9c53afeaa75a19a4b0f299f7
5
5
  SHA512:
6
- metadata.gz: 4af5bcc317b7468ed0eae22689a7d233b129d23179ef03910d6afadd1283c3b7e5f9de7af7468b40ccccce2f445f9988cc43597bfc7d15c207c1dc3ce81b8c47
7
- data.tar.gz: 3641ff55ebaa1399101cf08637da7fd5b94c3e4f132634266883f8815845acdc682ea693431f191e770ca117cc8e7c5ddb7ffedb60cd1fbadc13681b4c46ff43
6
+ metadata.gz: f9295415b8375b8d5c9741b15371b2aebf0eb02dc75220a6d0f3ac16259d26f1dd60aefdc0f3bf96f8e5c959a4b34d81717efaa87309555f1bbfe28261797aa6
7
+ data.tar.gz: 26fedef5b3779e49f656410a5fbfc7cbf8997d2a7ac627015681372a5e61dc1392116ed95a46662143f1fdd1ea628a8b5aaaf6b0e7f45b08a42189f27a5e7cca
@@ -59,7 +59,41 @@ class AbstractFeature < ActiveRecord::Base
59
59
  else "ST_Transform(ST_SetSRID(ST_Point(:lng, :lat), 4326), #{detect_srid(geom)})"
60
60
  end
61
61
 
62
- where("ST_DWithin(features.#{geom}, #{point_sql}, :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
62
+ binds = { :lng => lng.to_d, :lat => lat.to_d }
63
+
64
+ within_distance_of_sql(point_sql, distance_in_meters, geom, **binds)
65
+ end
66
+
67
+ def self.within_distance_of_line(points, distance_in_meters, geom = 'geom_lowres')
68
+ point_sql =
69
+ case geom.to_s
70
+ when 'geog' then ':points'
71
+ else "ST_Transform(ST_SetSRID(:points::geometry, 4326), #{detect_srid(geom)})"
72
+ end
73
+
74
+ binds = { :points => "LINESTRING(#{points.map {|coords| coords.join(' ') }.join(', ')})" }
75
+
76
+ within_distance_of_sql(point_sql, distance_in_meters, geom, **binds)
77
+ end
78
+
79
+ def self.within_distance_of_polygon(points, distance_in_meters, geom = 'geom_lowres')
80
+ point_sql =
81
+ case geom.to_s
82
+ when 'geog' then "ST_Polygon(:points::geometry)"
83
+ else "ST_Transform(ST_Polygon(:points::geometry, 4326), #{detect_srid(geom)})"
84
+ end
85
+
86
+ binds = { :points => "LINESTRING(#{points.map {|coords| coords.join(' ') }.join(', ')})" }
87
+
88
+ within_distance_of_sql(point_sql, distance_in_meters, geom, **binds)
89
+ end
90
+
91
+ def self.within_distance_of_sql(geometry_sql, distance_in_meters, features_column = 'geom_lowres', **binds)
92
+ if distance_in_meters.to_f > 0
93
+ where("ST_DWithin(features.#{features_column}, #{geometry_sql}, :distance)", **binds, :distance => distance_in_meters)
94
+ else
95
+ where("ST_Intersects(features.#{features_column}, #{geometry_sql})", **binds)
96
+ end
63
97
  end
64
98
 
65
99
  def self.area_in_square_meters(geom = 'geom_lowres')
@@ -8,6 +8,12 @@ module SpatialExtensions
8
8
  end
9
9
  end
10
10
 
11
+ def abstract_clear_feature_update_errors(models)
12
+ Array.wrap(models).each do |model|
13
+ model.clear_feature_update_error_status
14
+ end
15
+ end
16
+
11
17
  def abstract_proximity_action(scope, target, distance, &block)
12
18
  @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')
13
19
  @target = target
@@ -6,12 +6,18 @@ module SpatialFeatures
6
6
  def self.update_cached_status(record, method_name, state)
7
7
  return unless record.has_attribute?(:spatial_processing_status_cache)
8
8
 
9
- cache = record.spatial_processing_status_cache || {}
9
+ cache = record.spatial_processing_status_cache
10
10
  cache[method_name] = state
11
11
  record.spatial_processing_status_cache = cache
12
12
  record.update_column(:spatial_processing_status_cache, cache) if record.will_save_change_to_spatial_processing_status_cache?
13
13
  end
14
14
 
15
+ def spatial_processing_status_cache
16
+ value = super
17
+ return {} unless value.is_a?(Hash)
18
+ return value
19
+ end
20
+
15
21
  def queue_update_spatial_cache(*args, priority: priority_offset + 1, **kwargs)
16
22
  queue_spatial_task('update_spatial_cache', *args, priority:, **kwargs)
17
23
  end
@@ -29,6 +35,12 @@ module SpatialFeatures
29
35
  end
30
36
  end
31
37
 
38
+ def clear_feature_update_error_status
39
+ with_lock do
40
+ SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, :update_features!, nil) if updating_features_failed?
41
+ end
42
+ end
43
+
32
44
  def updating_features_failed?
33
45
  spatial_processing_status(:update_features!) == :failure
34
46
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "3.6.3"
2
+ VERSION = "3.8.0"
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: 3.6.3
4
+ version: 3.8.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: 2024-03-13 00:00:00.000000000 Z
12
+ date: 2024-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails