# How is Topographic Position Index calculated?

My understanding of how topographic position index is calculated is:

TPI = cell value - (mean of cell values within defined neighborhood)

But, I see that Weiss' original poster (http://www.jennessent.com/downloads/tpi-poster-tnc_18x22.pdf) was a little bit different than this.

tpi = int((dem - focalmean(dem, annulus, irad, orad)) + .5)

This part is essentially what I described - (dem - focalmean(dem, annulus, irad, orad). The annualus, irad, and orad terms just allow for an annulus of a defined size to be used rather than a continuous neighborhood.

Why is the "+.5" included and the "int()"? Weiss stated, "This poster presents an algorithm, implemented in GRID." I'm not familiar with GRID, was "int()" a function to integer-ize a value?

SAGA cites Weiss' posted for the calculation of TPI, does that mean that the algorithm in SAGA uses the "int()" and "+.5"?

• Adding a half and integerizing the result is a standard way to round floating-point values to integer. Jul 3, 2020 at 20:42
• @Vince, what is the logic behind adding .5 before integerizing? Jul 3, 2020 at 20:53
• What would happen to the values 2.99, 2.75, and 2.50 if you didn't? Jul 3, 2020 at 21:02
• From my understanding, if you did not at .5, the final values would be 3, 3, and 3. If you did at .5, the values would become 3.49, 3.25, and 3.00 and after integerizing the final values would be 3, 3, and 3. What am I missing? Jul 3, 2020 at 23:17
• No, you'd get 2, 2, and 2. The `Int` function in the Grid environment truncates to the integer below the value. Jul 3, 2020 at 23:36