spatial_features 3.7.0 → 3.8.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: 301894cdb34ba62e4176add97fdd2462e4618cabdc7d86af8ff28113ea35fe13
4
- data.tar.gz: 2d89a66243c80d8333f3825721c7fe0da008302d097a6f4033e97231b2052433
3
+ metadata.gz: 20b15f8be8e82ecb943e33fa81f3ccb2a98981fcc0a6143c282ba5e86dd1021f
4
+ data.tar.gz: d8ce7b591e57b0c7ada43af9f7db1ca415d7c88cf156d8394348ba67b717b216
5
5
  SHA512:
6
- metadata.gz: 2d483dddd5d794a4a1cacee046abb80d1ac91301e48f4b108adb9cc7b8bdc7ba72cb0aee80a559fbdecb8896094ee51fc957d41ee8dfb069ffc51d101efffd8d
7
- data.tar.gz: 3500d719c5c216a5667e70ba85460b72bfcfd62a3fc0a9351f67f7627baa94461c836bf315defeeb00f3de5ee5bc3ff1e4aea128cfb642905fc1400347a1b45d
6
+ metadata.gz: 71de22c18001e7b74ffc8f2caa98b5761cd92ea0c30dbf0bfdbb46f3d101b3806c44145bb897e69c4d9f2a929c07cde571490b3f2117549c6b010157c787e167
7
+ data.tar.gz: a4f3e57ac9e560dc641da35f499a3f39f73e61f1e39867a2762b51dfceb70b117ad4019ad304ae18b18338334a8297de8d65bf5bcc672bb0b6859fb90635329d
data/README.md CHANGED
@@ -24,22 +24,33 @@ Adds spatial methods to a model.
24
24
 
25
25
  CREATE TABLE features (
26
26
  id integer NOT NULL,
27
- type character varying(255),
28
27
  spatial_model_type character varying(255),
29
28
  spatial_model_id integer,
30
29
  name character varying(255),
31
- feature_type character varying(255),
32
- geog geography,
33
- geom geometry(Geometry,4326),
34
- geom_lowres geometry(Geometry,4326),
35
- tilegeom geometry(Geometry,3857),
36
- metadata hstore,
37
- area double precision,
38
- north numeric(9,6),
39
- east numeric(9,6),
40
- south numeric(9,6),
41
- west numeric(9,6),
42
- centroid geography,
30
+ geog public.geography,
31
+ metadata public.hstore DEFAULT ''::public.hstore NOT NULL,
32
+ geom public.geometry(Geometry,3005),
33
+ geom_lowres public.geometry(Geometry,3005),
34
+ type character varying,
35
+ source_identifier character varying,
36
+ tilegeom public.geometry(Geometry,3857) GENERATED ALWAYS AS (public.st_transform(geom, 3857)) STORED,
37
+ feature_type character varying GENERATED ALWAYS AS (
38
+ CASE public.geometrytype(geog)
39
+ WHEN 'POLYGON'::text THEN 'polygon'::text
40
+ WHEN 'MULTIPOLYGON'::text THEN 'polygon'::text
41
+ WHEN 'GEOMETRYCOLLECTION'::text THEN 'polygon'::text
42
+ WHEN 'LINESTRING'::text THEN 'line'::text
43
+ WHEN 'MULTILINESTRING'::text THEN 'line'::text
44
+ WHEN 'POINT'::text THEN 'point'::text
45
+ WHEN 'MULTIPOINT'::text THEN 'point'::text
46
+ ELSE NULL::text
47
+ END) STORED,
48
+ centroid public.geography GENERATED ALWAYS AS (public.st_pointonsurface((geog)::public.geometry)) STORED,
49
+ area numeric GENERATED ALWAYS AS (public.st_area(geog)) STORED,
50
+ north numeric GENERATED ALWAYS AS (public.st_ymax(((geog)::public.geometry)::public.box3d)) STORED,
51
+ east numeric GENERATED ALWAYS AS (public.st_xmax(((geog)::public.geometry)::public.box3d)) STORED,
52
+ south numeric GENERATED ALWAYS AS (public.st_ymin(((geog)::public.geometry)::public.box3d)) STORED,
53
+ west numeric GENERATED ALWAYS AS (public.st_xmin(((geog)::public.geometry)::public.box3d)) STORED
43
54
  );
44
55
 
45
56
  CREATE SEQUENCE features_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
@@ -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
@@ -44,6 +44,7 @@ module SpatialFeatures
44
44
  def kml_document
45
45
  @kml_document ||= begin
46
46
  doc = Nokogiri::XML(@data)
47
+ doc.remove_namespaces! # We don't care about namespaces since the document is going to be filled with placemark geometry and we want it all without needing to deal with namespaces
47
48
  raise ImportError, "Invalid KML document (root node was '#{doc.root&.name}')" unless doc.root&.name.to_s.casecmp?('kml')
48
49
  raise ImportError, "NetworkLink elements are not supported" unless doc.search('NetworkLink').empty?
49
50
  doc
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "3.7.0"
2
+ VERSION = "3.8.1"
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.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: 2024-05-16 00:00:00.000000000 Z
12
+ date: 2025-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails