Class: SpatialFeatures::Importers::Shapefile

Inherits:
Base
  • Object
show all
Defined in:
lib/spatial_features/importers/shapefile.rb

Constant Summary collapse

PROJ4_4326 =
'+proj=longlat +datum=WGS84 +no_defs'.freeze

Instance Attribute Summary

Attributes inherited from Base

#errors, #source_identifier, #warnings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#features

Constructor Details

#initialize(data, proj4: nil, **options) ⇒ Shapefile

Returns a new instance of Shapefile.



11
12
13
14
# File 'lib/spatial_features/importers/shapefile.rb', line 11

def initialize(data, proj4: nil, **options)
  super(data, **options)
  @proj4 = proj4
end

Class Method Details

.create_all(data, **options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/spatial_features/importers/shapefile.rb', line 20

def self.create_all(data, **options)
  Download.open_each(data, unzip: [/\.shp$/], downcase: true).map do |file|
    new(file, **options)
  end
rescue Unzip::PathNotFound => e
  # `INVALID_ARCHIVE` lives on `Importers::File` and isn't in this class's constant
  # lookup path, so the bare reference here raised NameError instead of the intended
  # ImportError whenever a model imported with `'Shapefile'` directly.
  raise ImportError, File.invalid_archive_message(e)
end

Instance Method Details

#cache_keyObject



16
17
18
# File 'lib/spatial_features/importers/shapefile.rb', line 16

def cache_key
  @cache_key ||= Digest::MD5.file(archive).to_s
end