Revert some PNG generation logic

pull/1493/head
Piero Toffanin 2022-07-07 12:14:59 -04:00
rodzic ba4fa0d555
commit c7b6fe52f3
1 zmienionych plików z 13 dodań i 17 usunięć

Wyświetl plik

@ -44,30 +44,26 @@ def generate_png(orthophoto_file, output_file=None, outsize=None):
# See if we need to select top three bands
bandparam = ""
gtif = gdal.Open(orthophoto_file)
if gtif.RasterCount > 4:
try:
bands = []
for idx in range(1, gtif.RasterCount+1):
bands.append(gtif.GetRasterBand(idx).GetColorInterpretation())
bands = []
for idx in range(1, gtif.RasterCount+1):
bands.append(gtif.GetRasterBand(idx).GetColorInterpretation())
bands = dict(zip(bands, range(1, len(bands)+1)))
bands = dict(zip(bands, range(1, len(bands)+1)))
red = bands.get(3)
green = bands.get(4)
blue = bands.get(5)
alpha = bands.get(6)
if alpha is not None:
bandparam = "-b %s -b %s -b %s -b %s -a_nodata 0" % (red, green, blue, alpha)
else:
bandparam = "-b %s -b %s -b %s -a_nodata 0" % (red, green, blue)
except Exception as e:
try:
red = bands.get(gdal.GCI_RedBand)
green = bands.get(gdal.GCI_GreenBand)
blue = bands.get(gdal.GCI_BlueBand)
bandparam = "-b %s -b %s -b %s -a_nodata 0" % (red, green, blue)
except:
bandparam = "-b 1 -b 2 -b 3 -a_nodata 0"
gtif = None
osparam = ""
if outsize is not None:
osparam = "-outsize %s 0 -ot Byte -scale 0 0.5 0 255" % outsize
else:
osparam = "-outsize %s%% %s%% ot Byte -scale 0 0.5 0 255" % (10, 10)
osparam = "-outsize %s 0" % outsize
system.run('gdal_translate -of png "%s" "%s" %s %s '
'--config GDAL_CACHEMAX %s%% ' % (orthophoto_file, output_file, osparam, bandparam, get_max_memory()))