ee.Number.expression Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Computes a numeric expression using a string mathematical expression and an optional dictionary of variables.
The expression string supports standard arithmetic, boolean, relational operators, Number functions, the '.' operator, and mathematical constants Math.PI and Math.E.
The
varsargument allows you to provide named values that can be referenced within the expression string.
| Usage | Returns |
|---|---|
ee.Number.expression(expression,vars) | Number |
| Argument | Type | Details |
|---|---|---|
expression | String | A mathematical expression string to be evaluated. In addition to the standard arithmetic, boolean and relational operators, expressions also support any function in Number, the '.' operator to extract child elements from the 'vars' dictionary, and mathematical constants Math.PI and Math.E. |
vars | Dictionary, default: null | A dictionary of named values that can be used in the expression. |
Examples
Code Editor (JavaScript)
// A dictionary of variables to use in expression.varvariables={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 setup
See the Python Environment page for information on the Python API and usinggeemap for interactive development.
importeeimportgeemap.coreasgeemap
Colab (Python)
# A dictionary of variables to use in expression.variables={'x':5,'y':10}# Arithmetic operators.display('x + y:',ee.Number.expression('x + y',variables))display('x - y:',ee.Number.expression('x - y',variables))display('x * y:',ee.Number.expression('x * y',variables))display('x / y:',ee.Number.expression('x / y',variables))display('x ** y:',ee.Number.expression('x ** y',variables))display('x % y:',ee.Number.expression('x % y',variables))# Logical operators.display('x || y:',ee.Number.expression('x || y',variables))display('x && y:',ee.Number.expression('x && y',variables))display('!(x):',ee.Number.expression('!(x)',variables))# Relational operators.display('x > y:',ee.Number.expression('x > y',variables))display('x >= y:',ee.Number.expression('x >= y',variables))display('x < y:',ee.Number.expression('x < y',variables))display('x <= y:',ee.Number.expression('x <= y',variables))display('x == y:',ee.Number.expression('x == y',variables))display('x != y:',ee.Number.expression('x != y',variables))# Conditional JavaScript (ternary) operator.display('(x < y) ? 100 : 1000):',ee.Number.expression('(x < y) ? 100 : 1000',variables))# Constants in the expression.display('100 * (x + y):',ee.Number.expression('100 * (x + y)',variables))# JavaScript Math constants.display('Math.PI:',ee.Number.expression('Math.PI',None))display('Math.E:',ee.Number.expression('Math.E',None))# Dot notation to call on child elements.display('Use dot notation to call on child elements:',ee.Number.expression('vals.x * vals.y',{'vals':variables}))# ee.Number functions.display('Use ee.Number add. add(x, y):',ee.Number.expression('add(x, y)',variables))display('Use ee.Number add and subtract. subtract(add(x, y), 5):',ee.Number.expression('subtract(add(x, y), 5)',variables))
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.