spatial_features 2.10.3 → 2.10.8

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: eb9c8e3383260110361e8adee25be15e7811937c7422a26c1559854de9577470
4
- data.tar.gz: 99306279256c88e034af0dfbe32035a1283d0604fc75634c4dbf6f78213295b6
3
+ metadata.gz: e304bd5be296e4094c384df03f72117452bce5bafc5364dd3277c9826c374f28
4
+ data.tar.gz: d0bddea53fc9210bbc192160c490b7ba8b85dcafc8ee6dc238f8f8f8d4ea6a43
5
5
  SHA512:
6
- metadata.gz: d6ec6a878142aa3dacf50f9df6d579d91cfa723e9e2206776157551cf4c2a2eb7de9ada41b2c734d5e371aa18b4f4ac9ac61cd08ace25b3da5b88b3c9bd0dc96
7
- data.tar.gz: bdbe282b14d9d57b35208d40c43bf987e29961febcf30d864beb1e43876cba178c96c74e5a4c895d48af7b6b9306e299f2e62ad9a2e6fcb2c495e07184fddb92
6
+ metadata.gz: bef25168be8628a563a5aff4026c3dd3de26ba5cbcd82ed6b3de155bfed59d6e8ac72af4f05b8a12f3755125772732fe14238f5ea9daccc6d62bfb8fc9739311
7
+ data.tar.gz: 9f0969a84cd00fca613384cbf8dfdd5989421de2b63c56db600729f94dc5c65a6333ba96dd99377b9339823bca8657fd7eaa51e1aff91abb8bfcd34bb3db9cb0
@@ -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)
@@ -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'
@@ -23,10 +23,17 @@ module SpatialFeatures
23
23
  yield OpenStruct.new data_from_wkt(record.geometry.as_text, proj4_projection).merge(:metadata => record.attributes) if record.geometry.present?
24
24
  end
25
25
  end
26
+ rescue Errno::ENOENT => e
27
+ case e.message
28
+ when /No such file or directory @ rb_sysopen - (.+)/
29
+ raise IncompleteShapefileArchive, "Shapefile archive is missing a required file: #{::File.basename($1)}"
30
+ else
31
+ raise e
32
+ end
26
33
  end
27
34
 
28
35
  def proj4_projection
29
- @proj4 ||= proj4_from_file || default_proj4_projection || raise(IndeterminateProjection, 'Could not determine shapefile projection. Check that `gdalsrsinfo` is installed.')
36
+ @proj4 ||= proj4_from_file || default_proj4_projection || raise(IndeterminateShapefileProjection, 'Could not determine shapefile projection. Check that `gdalsrsinfo` is installed.')
30
37
  end
31
38
 
32
39
  def proj4_from_file
@@ -45,11 +52,10 @@ module SpatialFeatures
45
52
  def file
46
53
  @file ||= Download.open(@data, unzip: /\.shp$/, downcase: true)
47
54
  end
48
-
49
-
50
- # ERRORS
51
-
52
- class IndeterminateProjection < StandardError; end
53
55
  end
56
+
57
+ # ERRORS
58
+ class IndeterminateShapefileProjection < SpatialFeatures::ImportError; end
59
+ class IncompleteShapefileArchive < SpatialFeatures::ImportError; end
54
60
  end
55
61
  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.3"
2
+ VERSION = "2.10.8"
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.3
4
+ version: 2.10.8
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-06 00:00:00.000000000 Z
12
+ date: 2020-05-28 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