-
Notifications
You must be signed in to change notification settings - Fork 3
/
TPI.js
72 lines (64 loc) · 1.85 KB
/
TPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var utils = require("users/aazuspan/geeTools:utils.js");
// Calculate topographic position index based on a DEM image, following Weiss 2001.
// Radius, window_shape, and units define the TPI kernel, and are passed to ee.Image.focal_mean
exports.tpi = function (dem, optionalParameters) {
// Default parameters
var params = {
radius: 300,
windowShape: "circle",
units: "meters",
};
params = utils.updateParameters(params, optionalParameters);
dem = dem.double();
var r = dem
.subtract(dem.focal_mean(params.radius, params.windowShape, params.units))
.add(0.5)
.int()
.rename("TPI");
return r;
};
// Reclassify a continuous TPI image into slope positions, following Weiss 2001
exports.slopePosition = function (tpi, slope, region, optionalParameters) {
var params = {
flatDegrees: 5,
scale: null,
maxPixels: 1e12,
};
params = utils.updateParameters(params, optionalParameters);
// Calculate the TPI standard deviation
var sd = tpi
.reduceRegion({
reducer: ee.Reducer.stdDev(),
geometry: region,
scale: params.scale,
maxPixels: params.maxPixels,
})
.getNumber(tpi.bandNames().get(0));
// Reclassify TPI to slope position
var tpiReclass = ee
.Image(0)
// Ridge
.where(tpi.gt(sd), 1)
// Upper slope
.where(tpi.gt(sd.multiply(0.5)).and(tpi.lte(sd)), 2)
// Middle slope
.where(
tpi
.gt(sd.multiply(-0.5))
.and(tpi.lt(sd.multiply(0.5)).and(slope.gt(params.flatDegrees))),
3
)
// Flat slope
.where(
tpi
.gte(sd.multiply(-0.5))
.and(tpi.lte(sd.multiply(0.5)).and(slope.lte(params.flatDegrees))),
4
)
// Lower slope
.where(tpi.gte(sd.multiply(-1)).and(tpi.lt(sd.multiply(-0.5))), 5)
// Valley
.where(tpi.lt(sd.multiply(-1)), 6)
.rename("slopePosition");
return tpiReclass;
};