spatial_features 3.0.1 → 3.0.2
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 +4 -4
- data/lib/spatial_features/download.rb +0 -7
- data/lib/spatial_features/has_spatial_features/feature_import.rb +8 -3
- data/lib/spatial_features/importers/base.rb +2 -1
- data/lib/spatial_features/importers/file.rb +2 -2
- data/lib/spatial_features/unzip.rb +3 -5
- data/lib/spatial_features/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57499f73e1190669ab1f3b5893c718db536fda282cce4a91bb0936908c5b2548
|
4
|
+
data.tar.gz: 0eb2e143c321b8e4e0dc498673d4a3c82e6d8d66df131a6ce445654a2f874772
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dca234339ac5c209752e01ae0eea025f8ad88e51480b73d4d5ec3beed2ebd019c58f4c96ba56a25f0655611474eea396ee0da0be8d13ece5db0b279d5de2e27
|
7
|
+
data.tar.gz: 72f3fbceb533ffad03a849cf7d3caed587749d0d3d3a6830538beb59787588fc67803c965b3ad7fed10512d3cc3aecdc9878f45c8cbf52a1656746289b3e598d
|
@@ -2,13 +2,6 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
module SpatialFeatures
|
4
4
|
module Download
|
5
|
-
# file can be a url, path, or file, any of which can return be a zipped archive
|
6
|
-
def self.read(file, unzip: nil, **unzip_options)
|
7
|
-
file = Download.open_each(file, unzip: unzip, **unzip_options).first
|
8
|
-
path = ::File.path(file)
|
9
|
-
return ::File.read(path)
|
10
|
-
end
|
11
|
-
|
12
5
|
# file can be a url, path, or file, any of which can return be a zipped archive
|
13
6
|
def self.open(file)
|
14
7
|
file = Kernel.open(file)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'digest/md5'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module SpatialFeatures
|
4
5
|
module FeatureImport
|
@@ -21,9 +22,10 @@ module SpatialFeatures
|
|
21
22
|
|
22
23
|
def update_features!(skip_invalid: false, **options)
|
23
24
|
options = options.reverse_merge(spatial_features_options)
|
25
|
+
tmpdir = options.fetch(:tmpdir) { Dir.mktmpdir("ruby_spatial_features") }
|
24
26
|
|
25
27
|
ActiveRecord::Base.transaction do
|
26
|
-
imports = spatial_feature_imports(options[:import], options[:make_valid])
|
28
|
+
imports = spatial_feature_imports(options[:import], options[:make_valid], options[:tmpdir])
|
27
29
|
cache_key = Digest::MD5.hexdigest(imports.collect(&:cache_key).join)
|
28
30
|
|
29
31
|
return if features_cache_key_matches?(cache_key)
|
@@ -49,6 +51,8 @@ module SpatialFeatures
|
|
49
51
|
else
|
50
52
|
raise ImportError, e.message, e.backtrace
|
51
53
|
end
|
54
|
+
ensure
|
55
|
+
FileUtils.remove_entry(tmpdir) if Dir.exist?(tmpdir)
|
52
56
|
end
|
53
57
|
|
54
58
|
def update_features_cache_key(cache_key)
|
@@ -73,10 +77,11 @@ module SpatialFeatures
|
|
73
77
|
|
74
78
|
private
|
75
79
|
|
76
|
-
def spatial_feature_imports(import_options, make_valid)
|
80
|
+
def spatial_feature_imports(import_options, make_valid, tmpdir)
|
77
81
|
import_options.flat_map do |data_method, importer_name|
|
78
82
|
Array.wrap(send(data_method)).flat_map do |data|
|
79
|
-
|
83
|
+
next unless data.present?
|
84
|
+
spatial_importer_from_name(importer_name).create_all(data, :make_valid => make_valid, :tmpdir => tmpdir)
|
80
85
|
end
|
81
86
|
end.compact
|
82
87
|
end
|
@@ -5,10 +5,11 @@ module SpatialFeatures
|
|
5
5
|
class Base
|
6
6
|
attr_reader :errors
|
7
7
|
|
8
|
-
def initialize(data, make_valid: false)
|
8
|
+
def initialize(data, make_valid: false, tmpdir: nil)
|
9
9
|
@make_valid = make_valid
|
10
10
|
@data = data
|
11
11
|
@errors = []
|
12
|
+
@tmpdir = tmpdir
|
12
13
|
end
|
13
14
|
|
14
15
|
def features
|
@@ -8,7 +8,7 @@ module SpatialFeatures
|
|
8
8
|
|
9
9
|
FILE_PATTERNS = [/\.kml$/, /\.shp$/, /\.json$/, /\.geojson$/]
|
10
10
|
def self.create_all(data, **options)
|
11
|
-
Download.open_each(data, unzip: FILE_PATTERNS, downcase: true).map do |file|
|
11
|
+
Download.open_each(data, unzip: FILE_PATTERNS, downcase: true, tmpdir: options[:tmpdir]).map do |file|
|
12
12
|
new(data, **options, current_file: file)
|
13
13
|
end
|
14
14
|
rescue Unzip::PathNotFound
|
@@ -23,7 +23,7 @@ module SpatialFeatures
|
|
23
23
|
# If no `current_file` is passed then we just take the first valid file that we find.
|
24
24
|
def initialize(data, *args, current_file: nil, **options)
|
25
25
|
begin
|
26
|
-
current_file ||= Download.open_each(data, unzip: FILE_PATTERNS, downcase: true).first
|
26
|
+
current_file ||= Download.open_each(data, unzip: FILE_PATTERNS, downcase: true, tmpdir: options[:tmpdir]).first
|
27
27
|
rescue Unzip::PathNotFound
|
28
28
|
raise ImportError, INVALID_ARCHIVE
|
29
29
|
end
|
@@ -16,21 +16,19 @@ module SpatialFeatures
|
|
16
16
|
return Array(paths)
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.extract(file_path,
|
19
|
+
def self.extract(file_path, tmpdir: nil, downcase: false)
|
20
|
+
tmpdir ||= Dir.mktmpdir
|
20
21
|
[].tap do |paths|
|
21
22
|
entries(file_path).each do |entry|
|
22
23
|
next if entry.name =~ IGNORED_ENTRY_PATHS
|
23
24
|
output_filename = entry.name
|
24
25
|
output_filename = output_filename.downcase if downcase
|
25
|
-
path = "#{
|
26
|
+
path = "#{tmpdir}/#{output_filename}"
|
26
27
|
FileUtils.mkdir_p(File.dirname(path))
|
27
28
|
entry.extract(path)
|
28
29
|
paths << path
|
29
30
|
end
|
30
31
|
end
|
31
|
-
rescue => e
|
32
|
-
FileUtils.remove_entry(output_dir)
|
33
|
-
raise(e)
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.names(file_path)
|
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.0.
|
4
|
+
version: 3.0.2
|
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: 2022-02-
|
12
|
+
date: 2022-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|