公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.List.splice
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
從開始索引開始,從清單中移除 count 個元素,並在該位置插入其他內容。如果 start 為負數,則會從清單結尾開始倒數。
用量 | 傳回 |
---|
List.splice(start, count, other) | 清單 |
引數 | 類型 | 詳細資料 |
---|
這個:list | 清單 | |
start | 整數 | |
count | 整數 | |
other | 清單,預設值為空值 | |
範例
程式碼編輯器 (JavaScript)
// An ee.List object.
var list = ee.List([0, 1, 2, 3, 4]);
print('Original list', list);
// If "other" argument is null, elements at positions specified by "start" and
// "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element', list.splice({start: 2, count: 1, other: null}));
// If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element', list.splice(-2, 1));
// Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements', list.splice(1, 3));
// Insert elements from the "other" list without deleting existing elements
// by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));
// Replace existing elements with those from the "other" list by specifying the
// "start" position to replace and the "count" of proceeding elements. If
// length of "other" list is greater than "count", the remaining "other"
// elements are inserted, they do not replace existing elements.
print('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
# An ee.List object.
ee_list = ee.List([0, 1, 2, 3, 4])
print('Original list:', ee_list.getInfo())
# If "other" argument is None, elements at positions specified by "start" and
# "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element:',
ee_list.splice(start=2, count=1, other=None).getInfo())
# If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())
# Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())
# Insert elements from the "other" list without deleting existing elements
# by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())
# Replace existing elements with those from the "other" list by specifying the
# "start" position to replace and the "count" of proceeding elements. If
# length of "other" list is greater than "count", the remaining "other"
# elements are inserted, they do not replace existing elements.
print('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eList.splice()\u003c/code\u003e modifies a list by removing elements and inserting new ones at a specified position.\u003c/p\u003e\n"],["\u003cp\u003eIt takes \u003ccode\u003estart\u003c/code\u003e, \u003ccode\u003ecount\u003c/code\u003e, and \u003ccode\u003eother\u003c/code\u003e as arguments to control the modification process.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estart\u003c/code\u003e determines the starting position for removal/insertion, while \u003ccode\u003ecount\u003c/code\u003e determines the number of elements to remove.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eother\u003c/code\u003e provides the elements to insert; if \u003ccode\u003eother\u003c/code\u003e is null or None, elements are only removed.\u003c/p\u003e\n"],["\u003cp\u003eA negative \u003ccode\u003estart\u003c/code\u003e value counts backwards from the end of the list for positioning.\u003c/p\u003e\n"]]],[],null,["# ee.List.splice\n\nStarting at the start index, removes count elements from list and insert the contents of other at that location. If start is negative, it counts backwards from the end of the list.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------|---------|\n| List.splice`(start, count, `*other*`)` | List |\n\n| Argument | Type | Details |\n|--------------|---------------------|---------|\n| this: `list` | List | |\n| `start` | Integer | |\n| `count` | Integer | |\n| `other` | List, default: null | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// An ee.List object.\nvar list = ee.List([0, 1, 2, 3, 4]);\nprint('Original list', list);\n\n// If \"other\" argument is null, elements at positions specified by \"start\" and\n// \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element', list.splice({start: 2, count: 1, other: null}));\n\n// If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element', list.splice(-2, 1));\n\n// Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements', list.splice(1, 3));\n\n// Insert elements from the \"other\" list without deleting existing elements\n// by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));\n\n// Replace existing elements with those from the \"other\" list by specifying the\n// \"start\" position to replace and the \"count\" of proceeding elements. If\n// length of \"other\" list is greater than \"count\", the remaining \"other\"\n// elements are inserted, they do not replace existing elements.\nprint('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));\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\n# An ee.List object.\nee_list = ee.List([0, 1, 2, 3, 4])\nprint('Original list:', ee_list.getInfo())\n\n# If \"other\" argument is None, elements at positions specified by \"start\" and\n# \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element:',\n ee_list.splice(start=2, count=1, other=None).getInfo())\n\n# If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())\n\n# Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())\n\n# Insert elements from the \"other\" list without deleting existing elements\n# by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())\n\n# Replace existing elements with those from the \"other\" list by specifying the\n# \"start\" position to replace and the \"count\" of proceeding elements. If\n# length of \"other\" list is greater than \"count\", the remaining \"other\"\n# elements are inserted, they do not replace existing elements.\nprint('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())\n```"]]