ee.Number.clamp

Kẹp giá trị nằm trong phạm vi từ min đến max.

Cách sử dụngGiá trị trả về
Number.clamp(min, max)Số
Đối sốLoạiThông tin chi tiết
this: numberSố
minSố thực dấu phẩy độngGiá trị tối thiểu để kẹp.
maxSố thực dấu phẩy độngGiá trị tối đa để kẹp.

Ví dụ

Trình soạn thảo mã (JavaScript)

// Numbers within range are unaffected.
print('100 clamped to range [0,255]', ee.Number(100).clamp(0, 255));  // 100

// Numbers greater than max in range are set to max.
print('259 clamped to range [0,255]', ee.Number(259).clamp(0, 255));  // 255

// Numbers less than min in range are set to min.
print('-259 clamped to range [0,255]', ee.Number(-259).clamp(0, 255));  // 0

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Numbers within range are unaffected.
# 100
print('100 clamped to range [0,255]:', ee.Number(100).clamp(0, 255).getInfo())

# Numbers greater than max in range are set to max.
# 255
print('259 clamped to range [0,255]:', ee.Number(259).clamp(0, 255).getInfo())

# Numbers less than min in range are set to min.
# 0
print('-259 clamped to range [0,255]:', ee.Number(-259).clamp(0, 255).getInfo())