Class: NSWTopo::Shapefile::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/nswtopo/gis/shapefile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Source

Returns a new instance of Source.



11
12
13
# File 'lib/nswtopo/gis/shapefile.rb', line 11

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/nswtopo/gis/shapefile.rb', line 14

def path
  @path
end

Class Method Details

.===(path) ⇒ Object



4
5
6
7
8
9
# File 'lib/nswtopo/gis/shapefile.rb', line 4

def self.===(path)
  OS.ogrinfo "-ro", "-so", path
  true
rescue OS::Error
  false
end

Instance Method Details

#layer(**options) ⇒ Object



16
17
18
# File 'lib/nswtopo/gis/shapefile.rb', line 16

def layer(**options)
  Layer.new self, **options
end

#layer_infoObject



30
31
32
33
34
# File 'lib/nswtopo/gis/shapefile.rb', line 30

def layer_info
  OS.ogrinfo("-ro", "-so", @path).scan(/^\w*\d+: (.*?)(?: \(([\w\s]+)\))?$/).sort_by(&:first).map do |name, geom_type|
    geom_type ? "#{name} (#{geom_type.delete(?\s)})" : name
  end
end

#only_layerObject



20
21
22
23
24
25
26
27
28
# File 'lib/nswtopo/gis/shapefile.rb', line 20

def only_layer
  name, *others = OS.ogrinfo("-ro", "-so", @path).scan(/^\w*\d+: (.*?)(?: \([\w\s]+\))?$/).flatten
  return nil if others.any?
  return name if name
  File.basename(@path, File.extname(@path)).tap do |name|
    OS.ogrinfo "-ro", "-so", @path, name
  end
rescue OS::Error
end