Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước
ngày 15 tháng 4 năm 2025 phải
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
ee.Number.expression
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tính toán một biểu thức số.
| Cách sử dụng | Giá trị trả về |
|---|
ee.Number.expression(expression, vars) | Số |
| Đối số | Loại | Thông tin chi tiết |
|---|
expression | Chuỗi | Một chuỗi biểu thức toán học cần được đánh giá. Ngoài các toán tử số học, boolean và quan hệ tiêu chuẩn, biểu thức cũng hỗ trợ mọi hàm trong Số, toán tử "." để trích xuất các phần tử con từ từ điển "vars" và các hằng số toán học Math.PI và Math.E. |
vars | Từ điển, mặc định: null | Một từ điển gồm các giá trị được đặt tên có thể dùng trong biểu thức. |
Ví dụ
Trình soạn thảo mã (JavaScript)
// A dictionary of variables to use in expression.
var variables = {x: 5, y: 10};
// Arithmetic operators.
print('x + y',
ee.Number.expression('x + y', variables));
print('x - y',
ee.Number.expression('x - y', variables));
print('x * y',
ee.Number.expression('x * y', variables));
print('x / y',
ee.Number.expression('x / y', variables));
print('x ** y',
ee.Number.expression('x ** y', variables));
print('x % y',
ee.Number.expression('x % y', variables));
// Logical operators.
print('x || y',
ee.Number.expression('x || y', variables));
print('x && y',
ee.Number.expression('x && y', variables));
print('!(x)',
ee.Number.expression('!(x)', variables));
// Relational operators.
print('x > y',
ee.Number.expression('x > y', variables));
print('x >= y',
ee.Number.expression('x >= y', variables));
print('x < y',
ee.Number.expression('x < y', variables));
print('x <= y',
ee.Number.expression('x <= y', variables));
print('x == y',
ee.Number.expression('x == y', variables));
print('x != y',
ee.Number.expression('x != y', variables));
// Conditional (ternary) operator.
print('(x < y) ? 100 : 1000)',
ee.Number.expression('(x < y) ? 100 : 1000', variables));
// Constants in the expression.
print('100 * (x + y)',
ee.Number.expression('100 * (x + y)', variables));
// JavaScript Math constants.
print('Math.PI',
ee.Number.expression('Math.PI', null));
print('Math.E',
ee.Number.expression('Math.E', null));
// Dot notation to call on child elements.
print('Use dot notation to call on child elements',
ee.Number.expression('vals.x * vals.y', {vals: variables}));
// ee.Number functions.
print('Use ee.Number add: add(x, y)',
ee.Number.expression('add(x, y)', variables));
print('Use ee.Number add and subtract: subtract(add(x, y), 5)',
ee.Number.expression('subtract(add(x, y), 5)', variables));
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)
# A dictionary of variables to use in expression.
variables = {'x': 5, 'y': 10}
# Arithmetic operators.
print('x + y:',
ee.Number.expression('x + y', variables).getInfo())
print('x - y:',
ee.Number.expression('x - y', variables).getInfo())
print('x * y:',
ee.Number.expression('x * y', variables).getInfo())
print('x / y:',
ee.Number.expression('x / y', variables).getInfo())
print('x ** y:',
ee.Number.expression('x ** y', variables).getInfo())
print('x % y:',
ee.Number.expression('x % y', variables).getInfo())
# Logical operators.
print('x || y:',
ee.Number.expression('x || y', variables).getInfo())
print('x && y:',
ee.Number.expression('x && y', variables).getInfo())
print('!(x):',
ee.Number.expression('!(x)', variables).getInfo())
# Relational operators.
print('x > y:',
ee.Number.expression('x > y', variables).getInfo())
print('x >= y:',
ee.Number.expression('x >= y', variables).getInfo())
print('x < y:',
ee.Number.expression('x < y', variables).getInfo())
print('x <= y:',
ee.Number.expression('x <= y', variables).getInfo())
print('x == y:',
ee.Number.expression('x == y', variables).getInfo())
print('x != y:',
ee.Number.expression('x != y', variables).getInfo())
# Conditional JavaScript (ternary) operator.
print('(x < y) ? 100 : 1000):',
ee.Number.expression('(x < y) ? 100 : 1000', variables).getInfo())
# Constants in the expression.
print('100 * (x + y):',
ee.Number.expression('100 * (x + y)', variables).getInfo())
# JavaScript Math constants.
print('Math.PI:',
ee.Number.expression('Math.PI', None).getInfo())
print('Math.E:',
ee.Number.expression('Math.E', None).getInfo())
# Dot notation to call on child elements.
print('Use dot notation to call on child elements:',
ee.Number.expression('vals.x * vals.y', {'vals': variables}).getInfo())
# ee.Number functions.
print('Use ee.Number add. add(x, y):',
ee.Number.expression('add(x, y)', variables).getInfo())
print('Use ee.Number add and subtract. subtract(add(x, y), 5):',
ee.Number.expression('subtract(add(x, y), 5)', variables).getInfo())
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-29 UTC."],[],["`ee.Number.expression` evaluates a mathematical expression string. It accepts an `expression` string and an optional `vars` dictionary containing named values. The expression supports arithmetic, boolean, and relational operators, as well as functions found in `ee.Number` and constants like `Math.PI` and `Math.E`. Dot notation accesses nested dictionary elements. The function returns a numerical result, allowing complex computations. Examples include adding, subtracting, multiplying, applying logical operations, and conditional logic.\n"]]