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.

doGDALLayersHaveSameProj(layer1, layer2)

A function which tests whether two gdal compatiable layers are in the same projection/coordinate system. This is done using the GDAL SpatialReference function AutoIdentifyEPSG. If the identified EPSG codes are different then False is returned otherwise True.

findCommonExtentOnGrid(baseExtent, baseGrid, otherExtent, fullContain=True)

A function which calculates the common extent between two extents but defines output on grid with defined resolutions. Useful for finding common extent on a particular image grid.

  • baseExtent is a bbox (xMin, xMax, yMin, yMax) providing the base for the grid on which output will be defined.
  • baseGrid the size of the (square) grid on which output will be defined.
  • otherExtent is a bbox (xMin, xMax, yMin, yMax) to be intersected with the baseExtent.
  • fullContain is a boolean. True: moving output onto grid will increase size of bbox (i.e., intersection fully contained)
    False: move output onto grid will decrease size of bbox (i.e., bbox fully contained within intesection)

return:: bbox (xMin, xMax, yMin, yMax)

findExtentOnGrid(baseExtent, baseGrid, fullContain=True)

A function which calculates the extent but defined on a grid with defined resolution. Useful for finding extent on a particular image grid.

  • baseExtent is a bbox (xMin, xMax, yMin, yMax) providing the base for the grid on which output will be defined.
  • baseGrid the size of the (square) grid on which output will be defined.
  • fullContain is a boolean. True: moving output onto grid will increase size of bbox (i.e., intersection fully contained)
    False: move output onto grid will decrease size of bbox (i.e., bbox fully contained within intesection)

return:: bbox (xMin, xMax, yMin, yMax)

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).

getEPSGCode(gdalLayer)

Using GDAL to return the EPSG code for the input layer.

getEPSGCodeFromWKT(wktString)

Using GDAL to return the EPSG code for inputted WKT string.

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 (MinX, MaxX, MinY, MaxY)

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

getProjWKTFromVec(inVec)

A function which gets the WKT projection from the inputted vector file.

  • inVec - is a string with the input vector file name and path.

return:: WKT representation of projection

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.

getVecLayerExtent(inVec, layerName=None, computeIfExp=True)
  • inVec - is a string with the input vector file name and path.
  • layerName - is the layer for which extent is to be calculated (Default: None)
  • if None assume there is only one layer and that will be read.
  • computeIfExp - is a boolean which specifies whether the layer extent
    should be calculated (rather than estimated from header) even if that operation is computationally expensive.

return:: boundary box is returned (MinX, MaxX, MinY, MaxY)

getWKTFromEPSGCode(epsgCode)

Using GDAL to return the WKT string for inputted EPSG Code.

  • epsgCode integer variable of the epsg code.
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.

renameGDALLayer(cFileName, oFileName)

Rename all the files associated with a GDAL layer.

reprojPoint(inProjOSRObj, outProjOSRObj, x, y)

Reproject a point from ‘inProjOSRObj’ to ‘outProjOSRObj’ where they are gdal osgeo.osr.SpatialReference objects.

Returns x, y. (note if returning long, lat you might need to invert)

setImageNoDataValue(inImg, noDataValue, band=None)

A function to set the no data value for an image. If band is not specified sets value for all bands.

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.