imagewriter

Contains the ImageWriter class

class rios.imagewriter.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)[source]

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.

Example

import sys
from rios.imagereader import ImageReader
from rios.imagewriter import ImageWriter

inputs = [sys.argv[1],sys.argv[2]]
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[3],info=info,
            firstblock=out)
    else:
        writer.write(out)

writer.close(calcStats=True)
addAutoColorTable(autoColorTableType)[source]

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, approx_ok=False)[source]

Closes the open dataset

static deleteIfExisting(filename)[source]

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.

doubleCheckCreationOptions(drivername, creationoptions)[source]

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.

getCurrentBlock()[source]

Returns the number of the current block

getGDALDataset()[source]

Returns the underlying GDAL dataset object

reset()[source]

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)[source]

Puts the sequence into colName in the output file. See rios.rat.writeColumn for more information. You probably also want to call setThematic().

setColorTable(colortable, band=1)[source]

Sets the output color table. Pass a list of sequences of colors, or a 2d array, as per the docstring for rat.setColorTable().

setLayerNames(names)[source]

Sets the output layer names. Pass a list of layer names, one for each output band

setThematic()[source]

Sets the output file to thematic. If file is multi-layer, then all bands are set to thematic.

write(block)[source]

Writes the numpy block to the current location in the file, and updates the location pointer for next write

writeAt(block, xcoord, ycoord)[source]

writes the numpy block to the specified pixel coords in the file

rios.imagewriter.allnotNone(items)[source]
rios.imagewriter.anynotNone(items)[source]
rios.imagewriter.setDefaultDriver()[source]

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

  • $RIOS_DFLT_DRIVER
  • $RIOS_DFLT_DRIVEROPTIONS
  • $RIOS_DFLT_CREOPT_<drivername>

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.