-
Notifications
You must be signed in to change notification settings - Fork 13
MapAlgebra
This document is under development.
Pedro R. Andrade
It is possible to implement map algebra procedures in TerraME.
From wikipedia:
Map algebra is a set-based algebra for manipulating geographic data, proposed by Dr. Dana Tomlin in the early 1980s. It is a set of primitive operations in a geographic information system (GIS) which allows two or more raster layers ("maps") of similar dimensions to produce a new raster layer (map) using algebraic operations such as addition, subtraction etc.
Depending on the spatial neighborhood, GIS transformations are categorized into four classes: local, focal, global, and zonal. Local operations works on individual raster cells, or pixels. Focal operations work on cells and their neighbors, whereas global operations work on the entire layer. Finally, zonal operations work on areas of cells that share the same value. The input and output for each operator being map, the operators can be combined into a procedure or script, to perform complex tasks.[1]
When map algebra is performed in cells from local operations, different types of operations can be used: -Arithmetic operations uses basic mathematical functions like addition, subtraction, multiplication and division. -Statistical operations uses statistical operations such as minimum, maximum, average and median. -Relational operations compares cells using functions such as greater than, smaller than or equal to. -Trigonometric operations uses sine, cosine, tangent, arcsine between two or more raster layers. -Exponential and logarithmic operations use exponent and logarithm functions
An example to rename attributes is shown below.
The file amazonia.shp
from base package was created from the previous version of TerraLib (4)
and now needs to be updated to the current version (5). First we need to create a Project
with a Layer
containing the file. See the code below.
import("terralib")
proj = Project{
file = "amazonia.tview",
clean = true,
amazonia = filePath("amazonia.shp")
}
In the previous version of TerraLib, a cellular space had the attributes Lin
and Col
.
In version 5, the attributes are now
row
and col
. Additionally, in the previous version the fist line of the cellular space started from the bottom
and now it starts from the top. To consider these differences, we need to set the arguments xy
and zero
while loading a CellularSpace
.
The attributes x
and y
of the CellularSpace
are then created using this configuration.
cs = CellularSpace{
project = proj,
layer = "amazonia",
zero = "bottom",
xy = {"Col", "Lin"},
}
After loading the data, we can now create row
and col
from y
and x
, respectively.
As we want to rename an attribute from Col
to col
, it is necessary to set the
first one as nil
because they have the same lower case, and TerraLib requires that
attributes in a cellular space must have different lower cases.
forEachCell(cs, function(cell)
cell.row = cell.y
cell.col = cell.x
cell.Col = nil
end)
After that, we only need to save
the cellular space into a file.
The two new attributes need to be passed as second argument to save.
cs:save("myamazonia", {"row", "col"})
Now it is possible to load the CellularSpace
using only argument file
.
Neighborhoods and Maps now work properly.
cs = CellularSpace{
file = filePath("myamazonia.shp")
}
cs:createNeighborhood()
Map{
target = amazonia,
select = "defor_10",
min = 0,
max = 1,
slices = 8,
color = "RdYlGn",
invert = true
}
If you have comments, doubts or suggestions related to this document, please write a feedback to pedro.andrade <at> inpe.br.
Back to wiki or terrame.org.