RSGISLib Module

This namespace contains rsgislib Python bindings

Please be aware that the following variables have been defined to match enums within RSGISLib.

Data Types for images:

  • TYPE_UNDEFINED = 0
  • TYPE_8INT = 1
  • TYPE_16INT = 2
  • TYPE_32INT = 3
  • TYPE_64INT = 4
  • TYPE_8UINT = 5
  • TYPE_16UINT = 6
  • TYPE_32UINT = 7
  • TYPE_64UINT = 8
  • TYPE_32FLOAT = 9
  • TYPE_64FLOAT = 10

Methods for the Maximum Likelihood Classifier:

  • METHOD_SAMPLES = 0 # as calculated by ML
  • METHOD_AREA = 1 # priors set by the relative area
  • METHOD_EQUAL = 2 # priors all equal
  • METHOD_USERDEFINED = 3 # priors passed in to function
  • METHOD_WEIGHTED = 4 # priors by area but with a weight applied

Shape indexes used with RasterGIS:

  • SHAPE_SHAPENA = 0
  • SHAPE_SHAPEAREA = 1
  • SHAPE_ASYMMETRY = 2
  • SHAPE_BORDERINDEX = 3
  • SHAPE_BORDERLENGTH = 4
  • SHAPE_COMPACTNESS = 5
  • SHAPE_DENSITY = 6
  • SHAPE_ELLIPTICFIT = 7
  • SHAPE_LENGTH = 8
  • SHAPE_LENGTHWIDTH = 9
  • SHAPE_WIDTH = 10
  • SHAPE_MAINDIRECTION = 11
  • SHAPE_RADIUSLARGESTENCLOSEDELLIPSE = 12
  • SHAPE_RADIUSSMALLESTENCLOSEDELLIPSE = 13
  • SHAPE_RECTANGULARFIT = 14
  • SHAPE_ROUNDNESS = 15
  • SHAPE_SHAPEINDEX = 16

Methods of initialising KMEANS:

  • INITCLUSTER_RANDOM = 0
  • INITCLUSTER_DIAGONAL_FULL = 1
  • INITCLUSTER_DIAGONAL_STDDEV = 2
  • INITCLUSTER_DIAGONAL_FULL_ATTACH = 3
  • INITCLUSTER_DIAGONAL_STDDEV_ATTACH = 4
  • INITCLUSTER_KPP = 5

Methods of calculating distance:

  • DIST_UNDEFINED = 0
  • DIST_EUCLIDEAN = 1
  • DIST_MAHALANOBIS = 2
  • DIST_MANHATTEN = 3
  • DIST_MINKOWSKI = 4
  • DIST_CHEBYSHEV = 5
  • DIST_MUTUALINFO = 6

Methods of summerising data:

  • SUMTYPE_UNDEFINED = 0
  • SUMTYPE_MODE = 1
  • SUMTYPE_MEAN = 2
  • SUMTYPE_MEDIAN = 3
  • SUMTYPE_MIN = 4
  • SUMTYPE_MAX = 5
  • SUMTYPE_STDDEV = 6
  • SUMTYPE_COUNT = 7
  • SUMTYPE_RANGE = 8
  • SUMTYPE_SUM = 9
Constants specifying how bands should be treated when sharpening (see rsgislib.imageutils)
  • SHARP_RES_IGNORE = 0
  • SHARP_RES_LOW = 1
  • SHARP_RES_HIGH = 2
exception rsgislib.RSGISPyException(value)

A class representing the RSGIS exception.

class rsgislib.RSGISPyUtils

A class with useful utilities within RSGISLib.

deleteDIR(dirPath)

A function which will delete a directory, if files and other directories are within the path specified they will be recursively deleted as well. So becareful you don’t delete things within meaning it.

deleteFileWithBasename(filePath)

Function to delete all the files which have a path and base name defined in the filePath attribute.

findFile(dirPath, fileSearch)

Search for a single file with a path using glob. Therefore, the file path returned is a true path. Within the fileSearch provide the file name with ‘*’ as wildcard(s).

getEnvironmentVariable(var)

A function to get an environmental variable, if variable is not present returns None.

getFileExtension(gdalformat)

A function to get the extension for a given file format (NOTE, currently only KEA, GTIFF, HFA, PCI and ENVI are supported).

getGDALDataTypeFromImg(inImg)

Returns the GDAL datatype ENUM (e.g., GDT_Float32) for the inputted raster file

getGDALFormatFromExt(fileName)

Get GDAL format, based on filename

getImageBBOX(inImg)

A function to retrieve the bounding box in the spatial coordinates of the image. return [TLX, BRX, TLY, BRY]

getImageBandCount(inImg)

A function to retrieve the number of image bands in an image file. return nBands

getImageFiles(inImg)

A function which returns a list of the files associated (e.g., header etc.) with the input image file.

getImageNoDataValue(inImg, band=1)

A function to retrieve the no data value for the image (from band; default 1).

getImageRes(inImg)

A function to retrieve the image resolution. return xRes, yRes

getImageSize(inImg)

A function to retrieve the image size in pixels. return xSize, ySize

getRSGISLibDataType(gdaltype)

Convert from GDAL data type string to RSGISLib data type int.

getRSGISLibDataTypeFromImg(inImg)

Returns the rsgislib datatype ENUM (e.g., rsgislib.TYPE_8INT) for the inputted raster file

getUTMZone(inImg)

A function which returns a string with the UTM (XXN | XXS) zone of the input image but only if it is projected within the UTM projection/coordinate system.

getWKTProjFromImage(inImg)

A function which returns the WKT string representing the projection of the input image.

isNumber(strVal)

A function which tests whether the input string contains a number of not.

numProcessCores()

A functions which returns the number of processing cores available on the machine

readTextFile2List(file)

Read a text file into a list where each line is an element in the list.

readTextFileNoNewLines(file)

Read a text file into a single string removing new lines.

uidGenerator(size=6)

A function which will generate a ‘random’ string of the specified length based on the UUID

writeList2File(dataList, outFile)

Write a list a text file, one line per item.

class rsgislib.RSGISTime

Class to calculate run time for a function, format and print out (similar to for XML interface).

Need to call start before running function and end immediately after. Example:

t = RSGISTime()
t.start()
rsgislib.segmentation.clump(kMeansFileZonesNoSgls, initClumpsFile, gdalFormat, False, 0) 
t.end()

Note, this is only designed to provide some general feedback, for benchmarking the timeit module is better suited.

calcDiff(preceedStr=”, postStr=”)

Calculate time difference, format and print.

end(reportDiff=True, preceedStr=”, postStr=”)

End timer and optionally print difference. If preceedStr or postStr have a value then they will be used instead of the generic wording around the time.

preceedStr + time + postStr

start(printStartTime=False)

Start timer, optionally printing start time

rsgislib.getRSGISLibVersion()

Calls rsgis-config to get the version number.