spatial_features 2.10.4 → 2.10.9

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: 033d463978aa207a802ab2ecb1f295f33cd1c4f857905aba42c4266ada83383a
4
- data.tar.gz: 6306307bbf18320d1767ad9c73ae855edafbc2549b089db4afb4a86948492532
3
+ metadata.gz: a716f42ee3c557baa01ea0a9e209f58e7bfb94163059057c7ff6fe303018de09
4
+ data.tar.gz: 17b0fa1251fb09c2aef8d45f82adb89e2e5e141110c3b1a659b8f2b30ab28f07
5
5
  SHA512:
6
- metadata.gz: 104856341f7d7807012a9f2372682f78eebd867adea536fc98f9f97f62029b50d5176c09394e634d9837fd819923f2061e627d8f3ef0c60f91c2fe153d7a53f0
7
- data.tar.gz: 64411a07521f62d1c83213bd2c76cf7636d6321aa524c17a00a510be3fc8b003f66be0b43da9b38ae8d87e838ef0ef2a654b24037993c57cb4b1bed27cce426f
6
+ metadata.gz: 3281304f2c534c57c98a2842cbf4cd77b14c59f3d54169c9ef0e39bd78b1f07e8ab775fe05cf575ee3f7443a3b13468638bebf3a7508e2931acfd0f4bacc96ea
7
+ data.tar.gz: aaf5163cd6403673d418943585b20bd4817e6bfd4885fe08f4e663d29d003adfaa80e480f69554fe4f31522e4cbd9e695ac38c19d9797bbfe1d1c0fba5ccef4e
@@ -143,6 +143,10 @@ class AbstractFeature < ActiveRecord::Base
143
143
  @make_valid
144
144
  end
145
145
 
146
+ def wkt
147
+ ActiveRecord::Base.connection.select_value("SELECT ST_ASEWKT('#{geom}')")
148
+ end
149
+
146
150
  private
147
151
 
148
152
  def make_valid
@@ -131,7 +131,7 @@ module SpatialFeatures
131
131
  scope = scope.select(options[:columns])
132
132
 
133
133
  scope = scope.select("ST_Distance(features.geom, other_features.geom) AS distance_in_meters") if options[:distance]
134
- scope = scope.select("ST_Area(ST_Intersection(features.geom, other_features.geom)) AS intersection_area_in_square_meters") if options[:intersection_area]
134
+ scope = scope.select("ST_Area(ST_Intersection(ST_CollectionExtract(features.geom, 3), ST_CollectionExtract(other_features.geom, 3))) AS intersection_area_in_square_meters") if options[:intersection_area] # Use ST_CollectionExtract to avoid a segfault we've been seeing when intersecting certain geometry
135
135
 
136
136
  return scope
137
137
  end
@@ -141,13 +141,12 @@ module SpatialFeatures
141
141
  def spatial_join(other, buffer = 0, table_alias = 'features', other_alias = 'other_features', geom = 'geom_lowres')
142
142
  scope = features_scope(self).select("#{geom} AS geom").select(:spatial_model_id)
143
143
 
144
- other_scope = features_scope(other)
145
- other_scope_select_sql = "ST_Union(#{geom})"
146
- other_scope_select_sql = "ST_Buffer(#{other_scope_select_sql}, #{buffer})" if buffer&.positive?
147
- other_scope = other_scope.select("ST_Union(#{geom}) AS geom").select("#{other_scope_select_sql} AS buffered_geom")
148
-
144
+ other_scope = features_scope(other).select("ST_Union(#{geom}) AS geom")
149
145
  return joins(%Q(INNER JOIN (#{scope.to_sql}) AS #{table_alias} ON #{table_alias}.spatial_model_id = #{table_name}.id))
150
- .joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias} ON ST_Intersects(#{table_alias}.geom, #{other_alias}.buffered_geom)))
146
+ .joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias}
147
+ ON NOT ST_IsEmpty(#{table_alias}.geom) -- Can't ST_DWithin empty geometry
148
+ AND NOT ST_IsEmpty(#{other_alias}.geom) -- Can't ST_DWithin empty geometry
149
+ AND ST_DWithin(#{table_alias}.geom, #{other_alias}.geom, #{buffer})))
151
150
  end
152
151
 
153
152
  def features_scope(other)
@@ -184,7 +183,7 @@ module SpatialFeatures
184
183
  end
185
184
 
186
185
  def intersects?(other)
187
- self.class.intersecting(other).exists?(self)
186
+ self.class.unscoped { self.class.intersecting(other).exists?(id) }
188
187
  end
189
188
 
190
189
  def total_intersection_area_percentage(klass)
@@ -4,7 +4,11 @@ module SpatialFeatures
4
4
  module Importers
5
5
  class File < SimpleDelegator
6
6
  def initialize(data, *args)
7
- file = Download.open(data, unzip: [/\.kml$/, /\.shp$/], downcase: true)
7
+ begin
8
+ file = Download.open(data, unzip: [/\.kml$/, /\.shp$/], downcase: true)
9
+ rescue Unzip::PathNotFound
10
+ raise ImportError, "Archive did not contain a .kml or .shp file. Supported formats are KMZ, KML, and zipped ArcGIS shapefiles."
11
+ end
8
12
 
9
13
  case ::File.extname(file.path.downcase)
10
14
  when '.kml'
@@ -26,7 +26,7 @@ module SpatialFeatures
26
26
  rescue Errno::ENOENT => e
27
27
  case e.message
28
28
  when /No such file or directory @ rb_sysopen - (.+)/
29
- raise IncompleteShapefileArchive, "Shapefile archive was missing a required file: #{::File.basename($1)}"
29
+ raise IncompleteShapefileArchive, "Shapefile archive is missing a required file: #{::File.basename($1)}"
30
30
  else
31
31
  raise e
32
32
  end
@@ -7,7 +7,7 @@ module SpatialFeatures
7
7
 
8
8
  if find = Array.wrap(find).presence
9
9
  paths = paths.detect {|path| find.any? {|pattern| path.index(pattern) } }
10
- raise(ImportError, "No file matched #{find}") unless paths.present?
10
+ raise(PathNotFound, "Archive did not contain a file matching #{find}") unless paths.present?
11
11
  end
12
12
 
13
13
  return paths
@@ -44,5 +44,9 @@ module SpatialFeatures
44
44
  rescue EOFError
45
45
  return false
46
46
  end
47
+
48
+ # EXCEPTIONS
49
+
50
+ class PathNotFound < StandardError; end
47
51
  end
48
52
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.10.4"
2
+ VERSION = "2.10.9"
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: 2.10.4
4
+ version: 2.10.9
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: 2020-05-07 00:00:00.000000000 Z
12
+ date: 2020-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -18,9 +18,9 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '4.2'
21
- - - "<="
21
+ - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.1'
23
+ version: '5.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +28,9 @@ dependencies:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '4.2'
31
- - - "<="
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '5.2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: delayed_job_active_record
36
36
  requirement: !ruby/object:Gem::Requirement