公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
延後執行
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
「用戶端與伺服器」文件說明如何在指向用戶端或伺服器端的程式碼中引用物件。完整的指令碼不僅包含您要使用的物件,還包含一組指示,告訴 Earth Engine 如何處理這些物件。本文件說明如何將這些指示傳送至 Google 進行處理,以及如何將結果傳回用戶端進行顯示。
在 Earth Engine 中編寫指令碼 (JavaScript 或 Python) 時,該程式碼並不會直接在 Google 的 Earth Engine 伺服器上執行。相反地,用戶端程式庫會將指令碼編碼為一組 JSON 物件,將物件傳送至 Google,然後等待回應。每個物件都代表一組作業,這些作業是取得特定輸出內容 (例如在用戶端顯示的圖片) 所需的作業。請考慮使用以下程式碼:
程式碼編輯器 (JavaScript)
var image = ee.Image('CGIAR/SRTM90_V4');
var operation = image.add(10);
print(operation.toString());
print(operation);
Python 設定
請參閱「
Python 環境」頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
image = ee.Image('CGIAR/SRTM90_V4')
operation = image.add(10)
print(operation)
print(operation.getInfo())
第一個列印陳述式會輸出 JSON 結構,用戶端程式庫會使用該結構向 Google 伺服器描述該圖片:
ee.Image({
"type": "Invocation",
"arguments": {
"image1": {
"type": "Invocation",
"arguments": {
"id": "CGIAR/SRTM90_V4"
},
"functionName": "Image.load"
},
"image2": {
"type": "Invocation",
"arguments": {
"value": 10
},
"functionName": "Image.constant"
}
},
"functionName": "Image.add"
})
第二個列印陳述式會將要求傳送給 Google,並輸出 Google 伺服器的 POST 回應。如要查看完整的 JSON 回應,請點選主控台右側印出物件旁的 JSON
連結:
{
"type": "Image",
"bands": [
{
"id": "elevation",
"data_type": {
"type": "PixelType",
"precision": "int",
"min": -32758,
"max": 32777
},
"crs": "EPSG:4326",
"crs_transform": [
0.0008333333535119891,
0,
-180,
0,
-0.0008333333535119891,
60
]
}
]
}
除非有相關要求,否則系統不會將任何內容傳送給 Google 處理。在這個範例中,在伺服器物件上列印 getInfo()
呼叫的結果會觸發要求。在明確要求結果之前,伺服器不會進行任何處理。請注意,JavaScript 程式碼編輯器中的 print()
是用來包裝非同步 getInfo()
呼叫的特殊用戶端函式;對於 Python,我們會直接呼叫該函式。
另一個要求範例是將要求顯示在程式碼編輯器或 geemap 地圖元素上。當這項要求傳送至 Google 時,系統只會傳回在 Code Editor 或 geemap 地圖元素中顯示結果所需的圖塊。具體來說,地圖的位置和縮放等級會決定哪些資料會經過處理,並轉換為可在地圖上顯示的圖片。請注意,如果您拖曳或縮放,其他圖塊會以延遲方式計算。這套按需系統可進行平行處理,並且能有效處理,但這也表示地圖上顯示的圖片會根據縮放等級和地圖邊界的位置,從不同的輸入內容產生。如要進一步瞭解如何根據要求決定運算的輸入內容,請參閱 Scale 文件。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eEarth Engine code execution involves encoding scripts into JSON objects by the client library and sending them to Google servers for processing, with results returned to the client for display.\u003c/p\u003e\n"],["\u003cp\u003eProcessing on Google servers is triggered only when there's an explicit request, such as printing an object's information or displaying it on a map.\u003c/p\u003e\n"],["\u003cp\u003eEarth Engine employs a lazy processing system where only the necessary data for the current view is computed, improving efficiency and allowing for parallelization.\u003c/p\u003e\n"],["\u003cp\u003eThe displayed image on the map depends on the zoom level and map bounds, resulting in different inputs being used for computation at various scales.\u003c/p\u003e\n"],["\u003cp\u003eFurther details on how inputs are determined for computations based on requests can be found in the Scale documentation.\u003c/p\u003e\n"]]],[],null,["# Deferred Execution\n\nThe [Client vs. Server](/earth-engine/guides/client_server) doc describes how objects referenced\nin your script can be either client-side or server-side. The complete script contains\nnot only the objects you want to use, but also a set of instructions that tell Earth Engine\nwhat to do with them. This doc describes how those instructions are sent to Google for\nprocessing and how the results are sent back to the client for display.\n\nWhen you write a script in Earth Engine (either JavaScript or Python), that code does\nNOT run directly on Earth Engine servers at Google. Instead, the\n[client library](https://github.com/google/earthengine-api) encodes the\nscript into a set of [JSON](http://www.json.org/) objects, sends the objects\nto Google and waits for a response. Each object represents a set of operations\nrequired to get a particular output, an image to display in the client, for example.\nConsider the following code:\n\n### Code Editor (JavaScript)\n\n```javascript\nvar image = ee.Image('CGIAR/SRTM90_V4');\nvar operation = image.add(10);\nprint(operation.toString());\nprint(operation);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nimage = ee.Image('CGIAR/SRTM90_V4')\noperation = image.add(10)\nprint(operation)\nprint(operation.getInfo())\n```\n\nThe first print statement will output the JSON structure that the client library\nuses to describe that image to the server at Google: \n\n```gdscript\nee.Image({\n \"type\": \"Invocation\",\n \"arguments\": {\n \"image1\": {\n \"type\": \"Invocation\",\n \"arguments\": {\n \"id\": \"CGIAR/SRTM90_V4\"\n },\n \"functionName\": \"Image.load\"\n },\n \"image2\": {\n \"type\": \"Invocation\",\n \"arguments\": {\n \"value\": 10\n },\n \"functionName\": \"Image.constant\"\n }\n },\n \"functionName\": \"Image.add\"\n})\n \n```\n\nThe second print statement will send the request to Google and output the\n[POST](https://en.wikipedia.org/wiki/POST_(HTTP)) response from Google\nservers. To see the response in all its JSON glory, click the `JSON` link\non the right side of the console, next to the printed object: \n\n```carbon\n{\n \"type\": \"Image\",\n \"bands\": [\n {\n \"id\": \"elevation\",\n \"data_type\": {\n \"type\": \"PixelType\",\n \"precision\": \"int\",\n \"min\": -32758,\n \"max\": 32777\n },\n \"crs\": \"EPSG:4326\",\n \"crs_transform\": [\n 0.0008333333535119891,\n 0,\n -180,\n 0,\n -0.0008333333535119891,\n 60\n ]\n }\n ]\n}\n \n```\n\nNothing is sent to Google for processing until there is a request for it. In this\nexample, printing the result of a `getInfo()` call on a server object triggers a\nrequest. No processing is done on the server until that result is explicitly\nrequested. Note that `print()` in the JavaScript Code Editor is a special\nclient-side function that wraps an asynchronous `getInfo()` call; for Python we\ncall it directly.\n\nAnother example of requesting something is displaying it on the Code Editor or geemap map\nelement. When this request is sent to Google, only the tiles\nnecessary to display the result in the Code Editor or geemap map element are returned.\nSpecifically, the position of the map and the zoom level determine which data get processed\nand turned into images that can be displayed on the map. If you pan or zoom, note that\nother tiles are computed lazily. This on-demand system allows for parallelization and\nefficient processing, but also means that the image displayed on the map is produced from\ndifferent inputs depending on the zoom level and location of the map bounds. Learn more about\nhow inputs to a computation are determined from the request in the\n[Scale](/earth-engine/guides/scale) doc."]]