![見出し画像](https://assets.st-note.com/production/uploads/images/115386199/rectangle_large_type_2_0f68b66ec24a12e935b98fa8330487ab.png?width=800)
【R】DEMデータからTPIを繰り返し計算し比較する
概要
TPIの計算方法です.検索半径をいくつか変えて比較します
必要なパッケージの読み込み
必要なパッケージを読み込む。
library(raster)
library(dplyr)
ラスタデータの読み込み
# ラスタデータの読み込み
r <- raster("path/to/file/dem.tif")
検索セル数(半径)の設定とTPIの計算
# 検索セル数
radius <- c(2,4,6,8,10)
for(i in radius) {
# 円形範囲
window <- focalWeight(r, (i * (res(r)[1] + 0.00001)), type='circle', fillNA = T)
# 四角形範囲の場合
#window <- focalWeight(r, (radius * (res(r)[1] )), type='rectangle', fillNA = T)
# 重みづけなし
window[window[]>0] <- 1
# 集計ウィンドウの確認
window
# フォーカル統計(平均値を集計)
focal <- focal(r, w = window ,fun = mean , na.rm = TRUE)
# TPIの計算
TPI <- r - focal
assign(paste0("TPI_radius", i), TPI)
}
結果の確認
plot(r)
![](https://assets.st-note.com/img/1693894795905-hJnpXIYdY3.png?width=800)
plot(TPI_radius2)
![](https://assets.st-note.com/img/1693894796079-G2lIPOWBzT.png?width=800)
plot(TPI_radius4)
![](https://assets.st-note.com/img/1693894796319-qJyNTrg7Jn.png?width=800)
plot(TPI_radius6)
![](https://assets.st-note.com/img/1693894796504-zGkxJYdVJC.png?width=800)
plot(TPI_radius8)
![](https://assets.st-note.com/img/1693894796719-g8fLQHCEVD.png?width=800)
plot(TPI_radius10)
![](https://assets.st-note.com/img/1693894796917-Vi7mpU1inB.png?width=800)
この記事が気に入ったらサポートをしてみませんか?