Class: NSWTopo::Shapefile::Source
- Inherits:
-
Object
- Object
- NSWTopo::Shapefile::Source
- Defined in:
- lib/nswtopo/gis/shapefile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Source
constructor
A new instance of Source.
- #layer(**options) ⇒ Object
- #layer_info ⇒ Object
- #only_layer ⇒ Object
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
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/nswtopo/gis/shapefile.rb', line 14 def path @path end |
Class Method Details
Instance Method Details
#layer(**options) ⇒ Object
16 17 18 |
# File 'lib/nswtopo/gis/shapefile.rb', line 16 def layer(**) Layer.new self, ** end |
#layer_info ⇒ Object
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_layer ⇒ Object
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 |