spatial_features 3.7.0 → 3.8.0

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: 301894cdb34ba62e4176add97fdd2462e4618cabdc7d86af8ff28113ea35fe13
4
- data.tar.gz: 2d89a66243c80d8333f3825721c7fe0da008302d097a6f4033e97231b2052433
3
+ metadata.gz: 54f447bf36298072b9480e0f33faa93145d8f4dbdecd5d1422001f0202a25354
4
+ data.tar.gz: 2546213005b5fde86ed5732c9d408a9b1ee7f30d9c53afeaa75a19a4b0f299f7
5
5
  SHA512:
6
- metadata.gz: 2d483dddd5d794a4a1cacee046abb80d1ac91301e48f4b108adb9cc7b8bdc7ba72cb0aee80a559fbdecb8896094ee51fc957d41ee8dfb069ffc51d101efffd8d
7
- data.tar.gz: 3500d719c5c216a5667e70ba85460b72bfcfd62a3fc0a9351f67f7627baa94461c836bf315defeeb00f3de5ee5bc3ff1e4aea128cfb642905fc1400347a1b45d
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')
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "3.7.0"
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.7.0
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-05-16 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