spatial_features 2.3.1 → 2.4.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
  SHA1:
3
- metadata.gz: 4c680fd535f7a9774f215d2d98183b0f3738d3f5
4
- data.tar.gz: 26ce1595016848e915b4acf734a59bbe7b663263
3
+ metadata.gz: 5e0a3bff0a76b4cc7d6e569677d5ee9035f6da2b
4
+ data.tar.gz: 225c280e58e6af0b5ce3623a582acd599037f9ef
5
5
  SHA512:
6
- metadata.gz: 727c003d4531cd14a6bd3a146baa095471d4d343335fefa16086714d512c8a9fc8cda46dda25bb5964b037e32e8daa0cd46fe48acebde71db82b1a4c4ee14d91
7
- data.tar.gz: 13a9bfe5018579fa1e42aac6ada8272b81d867090206f422d0884b71cf93ffb8f0ce948c6b421a8e363cf8193097c0affb42bde10b6220f53ffabd6938870893
6
+ metadata.gz: a35b743e5e5f90c58a002bafe5f823dbf90f1b25974f54809a2cbbf8a4a4aeabb59ca55f59677ead4f9a4e08977385ed50bdcaa811a6bc8f93cd5c094fe429f6
7
+ data.tar.gz: 7eaab5ad9ea2087fd35962c518e3df8118911ae5450cd54a431314d1f90a159edb1813e866c5aa7dcc1d54805e1c7f04a4c0bcf7ddc5178a87b1c3f52d998943
data/README.md CHANGED
@@ -19,6 +19,9 @@ Adds spatial methods to a model.
19
19
 
20
20
  ```ruby
21
21
  execute("
22
+ CREATE EXTENSION hstore;
23
+ CREATE EXTENSION postgis;
24
+
22
25
  CREATE TABLE features (
23
26
  id integer NOT NULL,
24
27
  spatial_model_type character varying(255),
@@ -39,6 +42,16 @@ Adds spatial methods to a model.
39
42
  centroid geography,
40
43
  kml_centroid text
41
44
  );
45
+
46
+ CREATE SEQUENCE features_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
47
+ ALTER SEQUENCE features_id_seq OWNED BY features.id;
48
+ ALTER TABLE ONLY features ALTER COLUMN id SET DEFAULT nextval('features_id_seq'::regclass);
49
+ ALTER TABLE ONLY features ADD CONSTRAINT features_pkey PRIMARY KEY (id);
50
+
51
+ CREATE INDEX index_features_on_feature_type ON features USING btree (feature_type);
52
+ CREATE INDEX index_features_on_spatial_model_id_and_spatial_model_type ON features USING btree (spatial_model_id, spatial_model_type);
53
+ CREATE INDEX index_features_on_geom ON features USING gist (geom);
54
+ CREATE INDEX index_features_on_geom_lowres ON features USING gist (geom_lowres);
42
55
 
43
56
  CREATE TABLE spatial_caches (
44
57
  id integer NOT NULL,
@@ -50,6 +63,13 @@ Adds spatial methods to a model.
50
63
  intersection_cache_distance double precision,
51
64
  features_hash character varying(255)
52
65
  );
66
+
67
+ CREATE SEQUENCE spatial_caches_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
68
+ ALTER SEQUENCE spatial_caches_id_seq OWNED BY spatial_caches.id;
69
+ ALTER TABLE ONLY spatial_caches ALTER COLUMN id SET DEFAULT nextval('spatial_caches_id_seq'::regclass);
70
+ ALTER TABLE ONLY spatial_caches ADD CONSTRAINT spatial_caches_pkey PRIMARY KEY (id);
71
+
72
+ CREATE INDEX index_spatial_caches_on_spatial_model ON spatial_caches USING btree (spatial_model_id, spatial_model_type);
53
73
 
54
74
  CREATE TABLE spatial_proximities (
55
75
  id integer NOT NULL,
@@ -60,6 +80,14 @@ Adds spatial methods to a model.
60
80
  distance_in_meters double precision,
61
81
  intersection_area_in_square_meters double precision
62
82
  );
83
+
84
+ CREATE SEQUENCE spatial_proximities_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
85
+ ALTER SEQUENCE spatial_proximities_id_seq OWNED BY spatial_proximities.id;
86
+ ALTER TABLE ONLY spatial_proximities ALTER COLUMN id SET DEFAULT nextval('spatial_proximities_id_seq'::regclass);
87
+ ALTER TABLE ONLY spatial_proximities ADD CONSTRAINT spatial_proximities_pkey PRIMARY KEY (id);
88
+
89
+ CREATE INDEX index_spatial_proximities_on_model_a ON spatial_proximities USING btree (model_a_id, model_a_type);
90
+ CREATE INDEX index_spatial_proximities_on_model_b ON spatial_proximities USING btree (model_b_id, model_b_type);
63
91
  ")
64
92
  ```
65
93
 
@@ -1,5 +1,5 @@
1
1
  class SpatialCache < ActiveRecord::Base
2
- belongs_to :spatial_model, :polymorphic => true, :inverse_of => :spatial_cache
2
+ belongs_to :spatial_model, :polymorphic => true, :inverse_of => :spatial_caches
3
3
 
4
4
  def self.between(spatial_model, klass)
5
5
  where(SpatialFeatures::Utils.polymorphic_condition(spatial_model, 'spatial_model'))
@@ -15,8 +15,8 @@ module SpatialFeatures
15
15
  end
16
16
 
17
17
  def self.update_spatial_cache(scope)
18
- scope.with_stale_spatial_cache.includes(:spatial_cache).find_each do |record|
19
- record.spatial_cache.each do |spatial_cache|
18
+ scope.with_stale_spatial_cache.includes(:spatial_caches).find_each do |record|
19
+ record.spatial_caches.each do |spatial_cache|
20
20
  cache_record_proximity(record, spatial_cache.intersection_model_type) if spatial_cache.stale?
21
21
  end
22
22
  end
@@ -59,7 +59,7 @@ module SpatialFeatures
59
59
  end
60
60
 
61
61
  def self.clear_record_cache(record, klass)
62
- record.spatial_cache.where(:intersection_model_type => klass).delete_all
62
+ record.spatial_caches.where(:intersection_model_type => klass).delete_all
63
63
  SpatialProximity.between(record, klass).delete_all
64
64
  end
65
65
 
@@ -14,11 +14,11 @@ module SpatialFeatures
14
14
  scope :with_features, lambda { joins(:features).uniq }
15
15
  scope :without_features, lambda { joins("LEFT OUTER JOIN features ON features.spatial_model_type = '#{name}' AND features.spatial_model_id = #{table_name}.id").where("features.id IS NULL") }
16
16
 
17
- scope :with_spatial_cache, lambda {|klass| joins(:spatial_cache).where(:spatial_caches => { :intersection_model_type => klass }).uniq }
17
+ scope :with_spatial_cache, lambda {|klass| joins(:spatial_caches).where(:spatial_caches => { :intersection_model_type => klass }).uniq }
18
18
  scope :without_spatial_cache, lambda {|klass| joins("LEFT OUTER JOIN #{SpatialCache.table_name} ON spatial_model_id = #{table_name}.id AND spatial_model_type = '#{name}' and intersection_model_type = '#{klass}'").where('spatial_model_id IS NULL') }
19
- scope :with_stale_spatial_cache, lambda { joins(:spatial_cache).where("#{table_name}.features_hash != spatial_caches.features_hash").uniq } if has_spatial_features_hash?
19
+ scope :with_stale_spatial_cache, lambda { joins(:spatial_caches).where("#{table_name}.features_hash != spatial_caches.features_hash").uniq } if has_spatial_features_hash?
20
20
 
21
- has_many :spatial_cache, :as => :spatial_model, :dependent => :delete_all
21
+ has_many :spatial_caches, :as => :spatial_model, :dependent => :delete_all, :class_name => 'SpatialCache'
22
22
  has_many :model_a_spatial_proximities, :as => :model_a, :class_name => 'SpatialProximity', :dependent => :delete_all
23
23
  has_many :model_b_spatial_proximities, :as => :model_b, :class_name => 'SpatialProximity', :dependent => :delete_all
24
24
 
@@ -98,7 +98,7 @@ module SpatialFeatures
98
98
  options = options.reverse_merge(:columns => "#{table_name}.*")
99
99
 
100
100
  # Don't use the cache if it doesn't exist
101
- return all.extending(UncachedRelation) unless other.spatial_cache_for?(Utils.class_of(self), buffer_in_meters)
101
+ return none.extending(UncachedResult) unless other.spatial_cache_for?(Utils.class_of(self), buffer_in_meters)
102
102
 
103
103
  scope = cached_spatial_join(other)
104
104
  scope = scope.select(options[:columns])
@@ -204,7 +204,7 @@ module SpatialFeatures
204
204
  end
205
205
 
206
206
  def spatial_cache_for?(other, buffer_in_meters)
207
- if cache = spatial_cache.between(self, SpatialFeatures::Utils.class_of(other)).first
207
+ if cache = spatial_caches.between(self, SpatialFeatures::Utils.class_of(other)).first
208
208
  return cache.intersection_cache_distance.nil? if buffer_in_meters.nil? # cache must be total if no buffer_in_meters
209
209
  return false if cache.stale? # cache must be for current features
210
210
  return true if cache.intersection_cache_distance.nil? # always good if cache is total
@@ -0,0 +1,4 @@
1
+ module SpatialFeatures
2
+ module UncachedResult
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.3.1"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -9,6 +9,7 @@ require 'google/apis/drive_v3'
9
9
 
10
10
  # LIB
11
11
  require 'spatial_features/caching'
12
+ require 'spatial_features/uncached_result'
12
13
  require 'spatial_features/venn_polygons'
13
14
  require 'spatial_features/controller_helpers/spatial_extensions'
14
15
  require 'spatial_features/download'
@@ -34,12 +35,6 @@ require 'spatial_features/importers/shapefile'
34
35
 
35
36
  require 'spatial_features/engine'
36
37
 
37
- module SpatialFeatures
38
- module UncachedRelation
39
- include ActiveRecord::NullRelation
40
- end
41
- end
42
-
43
38
  # Load the act method
44
39
  ActiveRecord::Base.send :extend, SpatialFeatures::ActMethod
45
40
  ActiveRecord::Base.send :extend, SpatialFeatures::FusionTables::ActMethod
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: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-13 00:00:00.000000000 Z
12
+ date: 2017-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '4.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.2'
28
28
  - !ruby/object:Gem::Dependency
@@ -170,6 +170,7 @@ files:
170
170
  - lib/spatial_features/importers/kml_file.rb
171
171
  - lib/spatial_features/importers/kml_file_arcgis.rb
172
172
  - lib/spatial_features/importers/shapefile.rb
173
+ - lib/spatial_features/uncached_result.rb
173
174
  - lib/spatial_features/unzip.rb
174
175
  - lib/spatial_features/utils.rb
175
176
  - lib/spatial_features/venn_polygons.rb