Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Python API Raster Operations

Johannes Kolbe edited this page Jun 30, 2014 · 7 revisions

Arithmetic Operations

The Python API for IlwisObjects supports basic arithmetic operations for use with RasterCoverages. The use is blindingly easy.

In the following code you can see some examples of possible operations. Note that the raster data does not need to have the same Georeference, so you can also take two RasterCoverages of the same area but with different Georeference data and perform arithmetic operations on them.

from ilwisobjects import *

Engine.setWorkingCatalog("file:///D:/<working>/<directory>/")

rc = RasterCoverage("n000302.mpr")
rctif = RasterCoverage("n0.mpr")

aa1 = rc + rctif
aa2 = rc + 2
aa3 = rc - rctif
aa4 = 2 - rc 
aa5 = rc + 3 * rctif
aa6 = rctif - 3 + rc / 2
aa7 = (rc + 3) * 5 + rctif / 5

In the above cases all aa variables represent a new RasterCoverage.

Mathematical Functions

In IlwisObjects it is also possible to work with more complex operations like sin, cos, log, ln, sqrt etc. For this to work you need to call the method do of the Engine class and pass the operator as a string and the coverage you want to use it on.

Engine.setWorkingCatalog("file:///D:/<working>/<directory>/")

rc = RasterCoverage("n000302.mpr")

aa1 = Engine.do("sin", rc)
aa2 = Engine.do("acos", rc)
aa3 = Engine.do("sqrt", rc)
aa4 = Engine.do("log10", rc)
aa5 = Engine.do("ln", rc)

Algorithms

Other operations that can be performed on Raster, as well as on Feature Covergase are different predefined algorithms. They work in a similar way to the mathematical functions. You also call them by using the Engine.do() function and as a first parameter you always have to pass the name of the operation you want to perform, depending on it you have to pass more input parameters.

To get a list of all available operations and their parameters you first have to create an instance of Engine(). Then you can use the method operations() to get a tuple, containing all existing algorithms you can use. To get the according list of parameters you have to use the operationsMetaData() function and pass it the name of a operation.

eng = Engine()

print(eng.operations())
#'setvaluerange', 'binarymathtable', 'selection', 'mastergeoreference', 'binarymathfeatures', 'binarymathraster',..... 

print(eng.operationMetaData("gridding")
#gridding(coordinatesystem,top-coordinate,x-cell-size, y-cell-size, horizontal-cells, vertical-cells)

csy = CoordinateSystem("code=proj4:+proj=utm +zone=35 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs")
polygongrid = Engine.do("gridding", csy, Coordinate(225358.6605, 3849480.5700), 1000.0, 1000.0, 12, 12)
# polygongrid is a new FeatureCoverage

Clone this wiki locally