公告 :凡是在
2025 年 4 月 15 日前 註冊使用 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 環境 頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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 ())
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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"]]