Contains the ImageWriter class
ImageWriter(filename, drivername='HFA', creationoptions=None, nbands=None, gdaldatatype=None, firstblock=None, info=None, xsize=None, ysize=None, transform=None, projection=None, windowxsize=None, windowysize=None, overlap=None)¶
This class is the opposite of the ImageReader class and is designed to be used in conjunction. The easiest way to use it is pass the info returned by the ImageReader for first iteration to the constructor. Otherwise, image size etc must be passed in.
The write() method can be used to write a block (numpy array)at a time to the output image - this is designed to be used at each iteration through the ImageReader object. Otherwise, the writeAt() method can be used to write blocks to arbitary locations.
import sys from rios.imagereader import ImageReader from rios.imagewriter import ImageWriter inputs = [sys.argv,sys.argv] reader = ImageReader(inputs) writer = None for (info, blocks) in reader: block1,block2 = blocks out = block1 * 4 + block2 if writer is None: writer = ImageWriter(sys.argv,info=info, firstblock=out) else: writer.write(out) writer.close(calcStats=True)
If autoColorTable has been set up for this output, then generate a color table of the requested type, and add it to the current file. This is called AFTER the Dataset has been closed, so is performed on the filename. This only applies to thematic layers, so when we open the file and find that the layers are athematic, we do nothing.
close(calcStats=False, statsIgnore=None, progress=None, omitPyramids=False, overviewLevels=[4, 8, 16, 32, 64, 128, 256, 512], overviewMinDim=33, overviewAggType=None, autoColorTableType=None)¶
Closes the open dataset
Delete the filename if it already exists. If possible, use the appropriate GDAL driver to do so, to ensure that any associated files will also be deleted.
Try to ensure that the given creation options are not incompatible with RIOS operations. Does not attempt to ensure they are totally valid, as that is GDAL’s job.
Returns a copy of creationoptions, possibly modified, or raises ImageOpenError in cases where the problem is not fixable.
Returns the number of the current block
Returns the underlying GDAL dataset object
Resets the location pointer so that the next write() call writes to the start of the file again
setAttributeColumn(colName, sequence, colType=None, bandNumber=1)¶
Puts the sequence into colName in the output file. See rios.rat.writeColumn for more information. You probably also want to call setThematic().
Sets the output color table. Pass a list of sequences of colors, or a 2d array, as per the docstring for rat.setColorTable().
Sets the output layer names. Pass a list of layer names, one for each output band
Sets the output file to thematic. If file is multi-layer, then all bands are set to thematic.
Writes the numpy block to the current location in the file, and updates the location pointer for next write
writeAt(block, xcoord, ycoord)¶
writes the numpy block to the specified pixel coords in the file
Sets some default values into global variables, defining what defaults we should use for GDAL driver. On any given output file these can be over-ridden, and can be over-ridden globally using the environment variables
If RIOS_DFLT_DRIVER is set, then it should be a gdal short driver name. If RIOS_DFLT_DRIVEROPTIONS is set, it should be a space-separated list of driver creation options, e.g. “COMPRESS=LZW TILED=YES”, and should be appropriate for the selected GDAL driver. This can also be ‘None’ in which case an empty list of creation options is passed to the driver.
The same rules apply to the driver-specific creation options given using $RIOS_DFLT_CREOPT_<driver>. These options are a later paradigm, and are intended to supercede the previous generic driver defaults.
If not otherwise supplied, the default is to use the HFA driver, with compression.
The code here is more complex than desirable, because it copes with legacy behaviour in the absence of the environment variables, and in the absence of the driver-specific option variables.