To begin we need to take the DEM and compute a mean filter on the data. Basically for each pixel a neighborhood statistic is calculated (e.g. mean, max min etc.). However, we need to first define the neighborhood. I decided to use a neighborhood of 3 by 3 pixels. The Switzerland DEM has a pixel resolution of 0.008333 degrees, this is about 1 km^2. Not exactly 1 km^2, but 928 by 1360 meters or 1.3 km^2. This means that for every pixel, R will calculate the average elevation of a 9 km^2 neighborhood. Essential this ends up smoothing out the DEM.

*et al.*2013). A positive value means that the pixel has an elevation higher than its 9 km^2 neighborhood and a negative means its lower. If you want you can calculate the TPI directly with the terrain function in the raster package.

- Ridges Zo > SD
- Upper Slope SD >= Zo > SD/2
- Middle Slope SD/2 >= Zo >= 0
- Flat Area 0 > Zo >= -SD/2
- Lower Slope -SD/2 > Zo >= -SD
- Valley Z0 < - SD

## References

*Geomorphology*,

*186*, pp.39-49.

Weiss, A., 2001, July. Topographic position and landforms analysis. In

*Poster presentation, ESRI user conference, San Diego, CA*(Vol. 200).