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
|