spatial_features 3.5.1 → 3.6.1

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: 58ed4738a69dce88104f9ad09ad32dc9f6ebe8819e6bd4bd87c30ea7bde58c70
4
- data.tar.gz: b70f376893db22e801ce2b1535c26390f02a754a6884938713ad292cac7432da
3
+ metadata.gz: b7cdd5c7e10977ad9a78fb31f28eb86dd05b1e62e0249f09b126f4ed4df90a19
4
+ data.tar.gz: 893d5e2d61574a7fcdedde78e5fde1e2a6ccf9d2a251bfd69cbcbcf8dcda89e9
5
5
  SHA512:
6
- metadata.gz: 9e0aa77934a5e00d891bb22adc72e3779267193035deaad0e236ced895c0565c06a6d4b81218e2d2708a493f9913fefdec10cac6e64b40d105cb0e0518f57ec4
7
- data.tar.gz: 9456cac927abb58f4710cbbc6366e5f906c93460e68013be9bd48cef90340d2ccf3d43d29e8ac8dff1752fc1c3950030aa494fbaffb3ca91e8ffc3ee179d8876
6
+ metadata.gz: 7ba7abf4e57f5bb8f76500e6b501b287e6b5b3ff09c5338b088900de2e9b993d4aa0365f305c52ba7febb6ff6ecf0606396026e4cae169767948a34b46bbd768
7
+ data.tar.gz: 976241133335d867dd74f05e5426b8f9281d88c126f30177e4c4f56a5e4509104dfe80f1ae4dc27bc1eaba265a079c8e2b2eaee4d0e7096a6ac136ed15c69daf
data/README.md CHANGED
@@ -106,7 +106,8 @@ Person.new(:features => [Feature.new(:geog => 'some binary PostGIS Geography str
106
106
  ### Import
107
107
 
108
108
  You can specify multiple import sources for geometry. Each key is a method that returns the data for the Importer, and
109
- each value is the Importer to use to parse the data. See each Importer for more details.
109
+ each value is the Importer to use to parse the data. Options can be passed in place of the Importer name, but must still
110
+ include a `name` key with the name of the importer. See each Importer for more details.
110
111
  ```ruby
111
112
  def ImageImporter
112
113
  def self.call(feature, image_paths)
@@ -117,8 +118,11 @@ def ImageImporter
117
118
  end
118
119
 
119
120
  class Location < ActiveRecord::Base
120
- has_spatial_features :import => { :remote_kml_url => 'KMLFile', :file => 'File', :geojson => 'ESRIGeoJSON' },
121
- :image_handlers => ['ImageImporter']
121
+ has_spatial_features :image_handlers => ['ImageImporter'],
122
+ :import => {
123
+ :remote_kml_url => { :name => 'KMLFile', :feature_name => lambda {|source_feature| source_feature.metadata['shapeID'] },
124
+ :file => 'File', :geojson => 'ESRIGeoJSON' }
125
+ }
122
126
 
123
127
  def remote_kml_url
124
128
  "www.test.com/kml/#{id}.kml"
@@ -88,10 +88,20 @@ module SpatialFeatures
88
88
  private
89
89
 
90
90
  def spatial_feature_imports(import_options, make_valid, tmpdir)
91
- import_options.flat_map do |data_method, importer_name|
91
+ import_options.flat_map do |data_method, configuration|
92
+ case configuration
93
+ when Hash
94
+ importer_name = configuration.fetch(:name)
95
+ options = configuration.except(:name)
96
+ else
97
+ importer_name = configuration
98
+ options = {}
99
+ end
100
+
92
101
  Array.wrap(send(data_method)).flat_map do |data|
93
102
  next unless data.present?
94
- spatial_importer_from_name(importer_name).create_all(data, :make_valid => make_valid, :tmpdir => tmpdir)
103
+
104
+ spatial_importer_from_name(importer_name).create_all(data, **options, :make_valid => make_valid, :tmpdir => tmpdir)
95
105
  end
96
106
  end.compact
97
107
  end
@@ -6,12 +6,13 @@ module SpatialFeatures
6
6
  attr_reader :errors
7
7
  attr_accessor :source_identifier # An identifier for the source of the features. Used to differentiate groups of features on the spatial model.
8
8
 
9
- def initialize(data, make_valid: false, tmpdir: nil, source_identifier: nil)
9
+ def initialize(data, make_valid: false, tmpdir: nil, source_identifier: nil, feature_name: ->(record) { record.name })
10
10
  @make_valid = make_valid
11
11
  @data = data
12
12
  @errors = []
13
13
  @tmpdir = tmpdir
14
14
  @source_identifier = source_identifier
15
+ @feature_name = feature_name
15
16
  end
16
17
 
17
18
  def features
@@ -51,13 +52,12 @@ module SpatialFeatures
51
52
  def build_feature(record)
52
53
  importable_image_paths = record.importable_image_paths if record.respond_to?(:importable_image_paths)
53
54
  Feature.new do |feature|
54
- feature.name = record.name
55
55
  feature.metadata = record.metadata
56
- feature.feature_type = record.feature_type
57
56
  feature.geog = record.geog
58
57
  feature.importable_image_paths = importable_image_paths
59
58
  feature.make_valid = @make_valid
60
59
  feature.source_identifier = source_identifier
60
+ feature.name = @feature_name.is_a?(Proc) ? @feature_name.call(record) : @feature_name
61
61
  end
62
62
  end
63
63
  end
@@ -22,9 +22,9 @@ module SpatialFeatures
22
22
  def each_record(&block)
23
23
  {'Polygon' => 'POLYGON', 'LineString' => 'LINE', 'Point' => 'POINT'}.each do |kml_type, sql_type|
24
24
  kml_document.css(kml_type).each do |feature|
25
- if placemark = feature.ancestors('Placemark').first
26
- name = placemark.css('name').text
25
+ if (placemark = feature.ancestors('Placemark').first)
27
26
  metadata = extract_metadata(placemark)
27
+ name = placemark.css('name').text
28
28
  else
29
29
  metadata = {}
30
30
  end
@@ -12,16 +12,6 @@ module SpatialFeatures
12
12
  rescue OpenURI::HTTPError
13
13
  raise ImportError, "ArcGIS Map Service not found. Ensure ArcGIS Server is running and accessible at #{path_or_url}."
14
14
  end
15
-
16
- private
17
-
18
- # ArcGIS includes metadata as an html table in the description
19
- def each_record(&block)
20
- super do |record|
21
- record.metadata = Hash[Nokogiri::XML(record.metadata[:description]).css('td').collect(&:text).each_slice(2).to_a]
22
- yield record
23
- end
24
- end
25
15
  end
26
16
  end
27
17
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "3.5.1"
2
+ VERSION = "3.6.1"
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: 3.5.1
4
+ version: 3.6.1
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: 2024-01-13 00:00:00.000000000 Z
12
+ date: 2024-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails