公告 :所有在
2025 年 4 月 15 日 之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件 ,才能继续使用 Earth Engine。如果您在 2025 年 9 月 26 日之前未完成验证,您的访问权限可能会被暂停。
发送反馈
ee.Number.expression
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
计算数值表达式。
用法 返回 ee.Number.expression(expression, vars )
数字
参数 类型 详细信息 expression
字符串 要计算的数学表达式字符串。除了标准的算术、布尔和关系运算符之外,表达式还支持 Number 中的任何函数、用于从“vars”字典中提取子元素的“.”运算符,以及数学常量 Math.PI 和 Math.E。 vars
字典,默认值:null 可在表达式中使用的命名值字典。
示例
代码编辑器 (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 ));
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境 页面。
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 ())
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-29。"],[],["`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"]]