Skip to content

Running map algebra

Dave Johnson edited this page Jan 15, 2015 · 2 revisions

In order to execute a map algebra script from the command line, you will need to understand how to run the mrgeo script. And of course you will need to understand the syntax and capabilities of map algebra itself.

The following is the "usage" output displayed when running the "mrgeo mapalgebra" command with no arguments:

usage: MapAlgebra
 -b,--buildPyramids            Build pyramids on the job output.
 -d,--debug                    Debug (very verbose) logging
 -e,--expression <arg>         Expression to calculate
 -l,--local-runner             Use Hadoop's local runner (used for
                               debugging)
 -o,--output <arg>             Output path
 -pl,--protectionLevel <arg>   Protection level
 -s,--script <arg>             Path to the script to execute
 -v,--verbose                  Verbose logging

Note that there are two ways to specify the map algebra script you wish to execute. You can either use the -e argument with the script on the command line itself, or you can use the -s argument and specify a file name containing the script.

If you use the -e argument, the next argument must be the map algebra script itself in double quotes. It's important to note that if you choose this approach, and your map algebra script itself requires the use of quotes, those embedded double quotes must be escaped on the command line with a backslash ().

Regardless of which approach you choose for including your map algebra script, the -o argument is also required for passing the name to use for the output. If the output already exists, it will be overwritten.

Enabling the building of pyramids is useful when you are producing output images that you want to be able to access later via TMS or WMS requests.

Example:

mrgeo-cmd/src/main/scripts/mrgeo mapalgebra -e "result = slope([myElevation]);" -o "mySlope"

# Using escape character for embedded quotes
mrgeo-cmd/src/main/scripts/mrgeo mapalgebra -e "result = RasterizeVector([/mrgeo/vectors/myFeatures.shp], \"MASK\", \"15z\", -92.0, 38.0, -89.0, 41.0);" -o myOutput