Contains the ViewerRAT class

class tuiview.viewerRAT.RATCache(gdalRAT, chunkSize)[source]

Class that caches a ‘chunk’ of the RAT


For calling from GUI. Qt will ask for a given row but we don’t want to re-read every time. Most requests will be around a location so we only update when we have to.


Shortcut to be called when a new column added saves having to re-read all the data - just updates the cache with the new data


Return the length of the current RAT chunk

getValueFromCol(colName, row)[source]

Return the actual value given name of col and a row count based on the full rat

setStartRow(startRow, colName=None)[source]

Call this to set the cache to contain the new data If colName is None all columns will be updated otherwise just the named one


Internal method, called when self.currStartRow changed If colName is None all columns will be updated, if it is a single name or a list of names, then just the named one(s) will be update.

updateColumn(colName, data, selectionArray)[source]

New data for a column. selectionArray is the size of the file’s RAT. data is just the subset for this cache. Updates only done where selectionArray == True (for the subset we are caching) updates cache and data in file

class tuiview.viewerRAT.ViewerRAT(*args: Any, **kwargs: Any)[source]

Represents an attribute table in memory. Has method to read from GDAL. Also will apply a user expression.


alias of int

addColumn(colname, coltype)[source]

Adds a new column with the specified name. Pass one of the NEWCOL constants as coltype.


rearrange self.columnNames given the preferred column order that is passed. Any columns not included in prefColOrder are tacked onto the end. Any columns in prefColOrder that don’t exist are ignored.


Removes attributes from this class

evaluateUserEditExpression(colName, expression, isselected, queryRow)[source]

Evaluate a user expression for editing and apply result to rat where isselected == True It is expected that a fragment of numpy code will be passed. numpy is provided in the global namespace. An exception is raised if code is invalid.

evaluateUserSelectExpression(expression, isselected, queryRow, lastselected)[source]

Evaluate a user expression for selection. It is expected that a fragment of numpy code will be passed. numpy is provided in the global namespace. An exception is raised if code is invalid, or does not return an array of bools.


Update the variables that define which are the columns in the colour table

static findVarNamesUsed(expression)[source]

Work out what variable names are used in the given expression. The variable names are those apart from the special ones provided for in getUserExpressionGlobals(), and is intended to be just those which might be column names. Returns a list of the variable name strings.


Creates a new cache object to cache chunks of the RAT


return the column names


Reads and entire column (in chunks) and returns a long array with all the data - for colour table use


return the preferred format string for a given column name


Return column to be used to lookup color table


get the number of columns


get the number of rows


Gets column names made sane. This means adding ‘_’ to Python keywords and replacing spaces with ‘_’ etc


return the type for a given column name


return the usage for a given column name

getUserExpressionGlobals(cache, isselected, queryRow, lastselected=None, colNameList=None)[source]

Get globals for user in user expression


Returns True if there are actually attributes in this class

static readColumnIndex(rat, colIndex)[source]

Read a column from the rat at index colIndex into a numpy array

static readColumnName(rat, colName)[source]

Same as readColumnIndex, but takes a name of column. Returns None if not found.

static readColumnOrderFromGDAL(gdaldataset)[source]

Reads the column order out of the gdaldataset. Returns empty list if none. Also returns the lookup column

readFromGDALBand(gdalband, gdaldataset)[source]

Reads attributes from a GDAL band Does nothing if no attribute table or file not marked as thematic.

setColumnToConstant(colName, value, isselected)[source]

Sets whole column to be a constant value (where isselected == True) for keyboard shortcuts etc

setFormat(colName, fmt)[source]

replace the format string for a given column name


Set column to be used to lookup color table


Given a GDAL dataset opened in update mode, writes the currently selected column order to the file (this can be changed by the querywindow) Ideally, this would be the band but writing metadata to the band causes problems with some Imagine files that have been opened in different versions of Imagine. Also writes the lookup column if there is one.

newProgress = 'QString'

Formats an exception for display and returns string