Module: NSWTopo::GDALGlob

Included in:
DEM, Vegetation
Defined in:
lib/nswtopo/gis/gdal_glob.rb

Instance Method Summary collapse

Instance Method Details

#gdal_raster?(format) ⇒ Boolean

Returns:

  • (Boolean)


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

def gdal_raster?(format)
  @gdal_formats ||= OS.gdalinfo("--formats").each_line.drop(1).map do |line|
    line.strip.split(?\s).first
  end - %w[PDF]
  @gdal_formats.include? format
end

#gdal_rasters(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nswtopo/gis/gdal_glob.rb', line 10

def gdal_rasters(path)
  paths = Array(path).flat_map do |path|
    Pathname.glob Pathname(path).expand_path
  end

  total = nil
  Enumerator.new do |yielder|
    while path = paths.pop
      OS.gdalmanage("identify", "-r", "-u", path).each_line.map do |line|
        line.chomp.split ": "
      end.each do |component, format|
        case
        when gdal_raster?(format) then yielder << component
        when path == component 
        when component !~ /\.zip$/
        else paths << "/vsizip/#{component}"
        end
      end
    end
  end.entries.tap do |paths|
    total = paths.length
  end.filter_map.with_index do |path, index|
    yield [index + 1, total] if block_given?
    info = JSON.parse OS.gdalinfo("-json", path)
    next unless info["geoTransform"]
    next unless @epsg || info.dig("coordinateSystem", "wkt")
    next path, info
  rescue JSON::ParserError
  end
end