nansat
nansat copied to clipboard
Bug in export when filename is same as sourcename
These lines from export() are supposed to handle the case where input and output files are the same. I would guess that the vrt parameter for add_band is an old parameter which has been removed. This piece of code does not work any longer.
if self.fileName == fileName:
numOfBands = self.vrt.dataset.RasterCount
# create VRT from each band and add it
for iBand in range(numOfBands):
vrt = VRT(array=self[iBand + 1])
self.add_band(vrt=vrt)
metadata = self.get_metadata(bandID=iBand + 1)
self.set_metadata(key=metadata,
bandID=numOfBands + iBand + 1)
# remove source bands
self.vrt.delete_bands(range(1, numOfBands))
Should we support overwriting the input file and solve this issue, or should we remove this code and throw an error when one tries to overwrite like this?
It would be nice to be able to update a netcdf file with new bands but, at the same time - maybe it's too risky, and therefore better to force creation of new files? The export function has a keyword argument "bands" which can be used to select which bands to export and thus not repeat anything in the new file..