spatial_features 1.6.1 → 1.7.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: c4613b63bcb5c5ac6eff245ae9c2cda4ef38b948
4
- data.tar.gz: 7f6d3a777c72868e754a3d452dc1f086bea2d194
3
+ metadata.gz: 10ff909874fdd64f019a564dda17df6d63d6b405
4
+ data.tar.gz: bfcdee15505529b1142110722312c793821f3f16
5
5
  SHA512:
6
- metadata.gz: caea9449c010f38ed4648254d3a67383be6cbcf79171c34e50e0a61af422da01561261a22e96c54ca3d4fa928f10b9aa92aefba28061337fe231168e5cb861d0
7
- data.tar.gz: aed8dea2e9ed4344aec3fb8aa4886143734cedc95a33677b9b642e62c377220ec482269626cb540dc9507a5def1863c48e1fd9da58923a9f1acf8fb50ed84e1d
6
+ metadata.gz: 59d516201f42433921e1def7cec21a42b17ba8340232dfef479b840b45c6e89334eced10212d47c3742b2c15f87a9d2ac50a17cca525847d861462f9b48a7d2a
7
+ data.tar.gz: 027192a3d69ebb10e98719fd1154e691d82ea2211faa925d785391a2f2325fd43caca1249476d8d590db9ad5ac49e66154dcd687fa8b27b4da61bd4631f6bf81
data/README.md CHANGED
@@ -21,7 +21,9 @@ execute("
21
21
  north numeric(9,6),
22
22
  east numeric(9,6),
23
23
  south numeric(9,6),
24
- west numeric(9,6)
24
+ west numeric(9,6),
25
+ centroid geography,
26
+ kml_centroid text
25
27
  );
26
28
 
27
29
  CREATE TABLE spatial_caches (
@@ -64,21 +64,23 @@ class Feature < ActiveRecord::Base
64
64
  options.reverse_merge! :lowres_simplification => 2, :lowres_precision => 5
65
65
 
66
66
  update_all <<-SQL.squish
67
- geom = ST_Transform(geog::geometry, #{detect_srid('geom')}),
68
- north = ST_YMax(geog::geometry),
69
- east = ST_XMax(geog::geometry),
70
- south = ST_YMin(geog::geometry),
71
- west = ST_XMin(geog::geometry),
72
- area = ST_Area(geog)
67
+ geom = ST_Transform(geog::geometry, #{detect_srid('geom')}),
68
+ north = ST_YMax(geog::geometry),
69
+ east = ST_XMax(geog::geometry),
70
+ south = ST_YMin(geog::geometry),
71
+ west = ST_XMin(geog::geometry),
72
+ area = ST_Area(geog),
73
+ centroid = ST_PointOnSurface(geog::geometry)
73
74
  SQL
74
75
 
75
76
  update_all <<-SQL.squish
76
- geom_lowres = ST_SimplifyPreserveTopology(geom, #{options[:lowres_simplification]})
77
+ geom_lowres = ST_SimplifyPreserveTopology(geom, #{options[:lowres_simplification]})
77
78
  SQL
78
79
 
79
80
  update_all <<-SQL.squish
80
- kml = ST_AsKML(geog, 6),
81
- kml_lowres = ST_AsKML(geom_lowres, #{options[:lowres_precision]})
81
+ kml = ST_AsKML(geog, 6),
82
+ kml_lowres = ST_AsKML(geom_lowres, #{options[:lowres_precision]}),
83
+ kml_centroid = ST_AsKML(centroid)
82
84
  SQL
83
85
  end
84
86
 
@@ -91,7 +93,9 @@ class Feature < ActiveRecord::Base
91
93
  end
92
94
 
93
95
  def kml(options = {})
94
- options[:lowres] ? kml_lowres : super()
96
+ geometry = options[:lowres] ? kml_lowres : super()
97
+ geometry = "<MultiGeometry>#{geometry}#{kml_centroid}</MultiGeometry>" if options[:centroid]
98
+ return geometry
95
99
  end
96
100
 
97
101
  private
@@ -10,7 +10,7 @@ module SpatialFeatures
10
10
  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") }
11
11
 
12
12
  scope :with_spatial_cache, lambda {|klass| joins(:spatial_cache).where(:spatial_caches => { :intersection_model_type => klass }).uniq }
13
- scope :without_spatial_cache, lambda {|klass| where.not(:id => with_spatial_cache(klass)) }
13
+ 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') }
14
14
  scope :with_stale_spatial_cache, lambda { joins(:spatial_cache).where("#{table_name}.features_hash != spatial_caches.features_hash").uniq } if has_spatial_features_hash?
15
15
 
16
16
  has_many :spatial_cache, :as => :spatial_model, :dependent => :delete_all
@@ -127,7 +127,7 @@ module SpatialFeatures
127
127
  end
128
128
 
129
129
  scope = scope.select("MIN(ST_Distance(features.geom, features_for_other.geom)) AS distance_in_meters") if options[:distance]
130
- scope = scope.select("ST_Area(ST_Intersection(ST_UNION(features.geom), ST_UNION(features_for_other.geom))) AS intersection_area_in_square_meters") if options[:intersection_area]
130
+ scope = scope.select("ST_Area(ST_UNION(ST_Intersection(features.geom, features_for_other.geom))) AS intersection_area_in_square_meters") if options[:intersection_area]
131
131
  return scope
132
132
  end
133
133
 
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "1.6.1"
2
+ VERSION = "1.7.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: 1.6.1
4
+ version: 1.7.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: 2016-08-04 00:00:00.000000000 Z
12
+ date: 2016-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails