# Weighted sum

This tool performs a weighted summation on multiple input images. This tool can be used to combine multiple factors with varying levels of weight or relative importance. For example, let's say that you wish to make a new variable that combines the influences of local slope gradient, elevation, and the wetness index, and that the relative importance, or weighting, of these three factors is 0.5, 0.2, and 0.3 respectively. If a particular grid cell has slope = 6.4, elevation = 200, and wetness index = 5.2 then the Weighted Sum tool will estimate the output value as:

`S = 6.4 × 0.5 + 200 × 0.2 + 5.2 × 0.3 = 44.76`

Note that the weights in the above example sum to one. In fact, the algorithm will convert the user-defined weights internally such that this is always the case. As such, the user can specify the relative weights as decimals, percentages, or relative weightings (e.g. slope is 2 times more important than elevation, in which case the weights may not sum to 1 or 100).

In the example above, the final sum is heavily influenced by the relatively large value of elevation, despite the fact that this factor has the lowest weighting. This occurs because each of the factors are not on a common scale (e.g. 0-1). In many GIS applications, e.g. multi-criteria evaluation (MCE), each of the factors contributing to the overlay must lie on the same data scale. To achieve this, you could first perform a Contrast Stretch, or more simply, you could use the Weighted Overlay tool. The Weighted Overlay tool is similar to Weighted Sum, however, it is more powerful because it automatically converts the input factors to a common, user-defined scale, and also allows the user to specify cost factors (i.e. those factors for which higher values are less suitable).

NoData valued grid cells in any of the input images will be assigned NoData values in the output image. The output raster is of the float data type and continuous data scale.

## Scripting:

The following is an example of a Python script that uses this tool:

``` wd = pluginHost.getWorkingDirectory() # image1;weight1;image2;weight2;... inputData = wd + "input1.dep" + ";" + "0.2" + ";" + wd + "input2.dep" + ";" + "0.8" outputFile = wd + "output.dep" args = [inputData, outputFile] pluginHost.runPlugin("WeightedSum", args, False) ```

This is a Groovy script also using this tool:

``` def wd = pluginHost.getWorkingDirectory() // image1;weight1;image2;weight2;... def inputData = wd + "input1.dep" + ";" + "0.2" + ";" + wd + "input2.dep" + ";" + "0.8" def outputFile = wd + "output.dep" String[] args = [inputData, outputFile] pluginHost.runPlugin("WeightedSum", args, false) ```

## Credits:

• John Lindsay (2012) email: jlindsay@uoguelph.ca