公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
反向联接
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
假设联接的目的是保留 primary
集合中不属于 secondary
集合的所有图片。您可以使用 ee.Join.inverted()
执行此类反向联接。
Code Editor (JavaScript)
// Load a Landsat 8 image collection at a point of interest.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filterBounds(ee.Geometry.Point(-122.09, 37.42));
// Define start and end dates with which to filter the collections.
var april = '2014-04-01';
var may = '2014-05-01';
var june = '2014-06-01';
var july = '2014-07-01';
// The primary collection is Landsat images from April to June.
var primary = collection.filterDate(april, june);
// The secondary collection is Landsat images from May to July.
var secondary = collection.filterDate(may, july);
// Use an equals filter to define how the collections match.
var filter = ee.Filter.equals({
leftField: 'system:index',
rightField: 'system:index'
});
// Define the join.
var invertedJoin = ee.Join.inverted();
// Apply the join.
var invertedJoined = invertedJoin.apply(primary, secondary, filter);
// Print the result.
print('Inverted join:', invertedJoined);
Python 设置
如需了解 Python API 以及如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# Load a Landsat 8 image collection at a point of interest.
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(
ee.Geometry.Point(-122.09, 37.42)
)
# Define start and end dates with which to filter the collections.
april = '2014-04-01'
may = '2014-05-01'
june = '2014-06-01'
july = '2014-07-01'
# The primary collection is Landsat images from April to June.
primary = collection.filterDate(april, june)
# The secondary collection is Landsat images from May to July.
secondary = collection.filterDate(may, july)
# Use an equals filter to define how the collections match.
filter = ee.Filter.equals(leftField='system:index', rightField='system:index')
# Define the join.
inverted_join = ee.Join.inverted()
# Apply the join.
inverted_joined = inverted_join.apply(primary, secondary, filter)
# Print the result.
display('Inverted join:', inverted_joined)
输出应如下所示:
Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140403 (17 bands)
Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140419 (17 bands)
反向联接包含 4 月 3 日和 4 月 19 日的图片,表示 primary
集合中存在但 secondary
集合中不存在的图片。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003e\u003ccode\u003eee.Join.inverted()\u003c/code\u003e allows you to keep images from a primary collection that do not have matching images in a secondary collection based on a specified filter.\u003c/p\u003e\n"],["\u003cp\u003eThis example demonstrates how to use \u003ccode\u003eee.Join.inverted()\u003c/code\u003e to identify Landsat 8 images from April that are not present in the May to July timeframe.\u003c/p\u003e\n"],["\u003cp\u003eAn \u003ccode\u003eee.Filter.equals()\u003c/code\u003e is employed to define matching criteria between the collections, typically using a common property like 'system:index'.\u003c/p\u003e\n"],["\u003cp\u003eThe resulting collection contains only images unique to the primary collection, effectively isolating images not found in the secondary collection.\u003c/p\u003e\n"]]],["The content demonstrates how to use `ee.Join.inverted()` to retain images from a `primary` collection that are absent in a `secondary` collection. It involves loading a Landsat 8 image collection and defining `primary` (April-June) and `secondary` (May-July) collections. An equals filter is used to match images by their system index. The `invertedJoin` is defined and applied, resulting in images present in the `primary` but not in the `secondary` collection, exemplified by images from April 3rd and 19th.\n"],null,["# Inverted Joins\n\nSuppose that the purpose of the join is to retain all images in the `primary`\ncollection that are not in the `secondary` collection. You can perform this\ntype of inverted join using `ee.Join.inverted()`.\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 image collection at a point of interest.\nvar collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterBounds(ee.Geometry.Point(-122.09, 37.42));\n\n// Define start and end dates with which to filter the collections.\nvar april = '2014-04-01';\nvar may = '2014-05-01';\nvar june = '2014-06-01';\nvar july = '2014-07-01';\n\n// The primary collection is Landsat images from April to June.\nvar primary = collection.filterDate(april, june);\n\n// The secondary collection is Landsat images from May to July.\nvar secondary = collection.filterDate(may, july);\n\n// Use an equals filter to define how the collections match.\nvar filter = ee.Filter.equals({\n leftField: 'system:index',\n rightField: 'system:index'\n});\n\n// Define the join.\nvar invertedJoin = ee.Join.inverted();\n\n// Apply the join.\nvar invertedJoined = invertedJoin.apply(primary, secondary, filter);\n\n// Print the result.\nprint('Inverted join:', invertedJoined);\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# Load a Landsat 8 image collection at a point of interest.\ncollection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(\n ee.Geometry.Point(-122.09, 37.42)\n)\n\n# Define start and end dates with which to filter the collections.\napril = '2014-04-01'\nmay = '2014-05-01'\njune = '2014-06-01'\njuly = '2014-07-01'\n\n# The primary collection is Landsat images from April to June.\nprimary = collection.filterDate(april, june)\n\n# The secondary collection is Landsat images from May to July.\nsecondary = collection.filterDate(may, july)\n\n# Use an equals filter to define how the collections match.\nfilter = ee.Filter.equals(leftField='system:index', rightField='system:index')\n\n# Define the join.\ninverted_join = ee.Join.inverted()\n\n# Apply the join.\ninverted_joined = inverted_join.apply(primary, secondary, filter)\n\n# Print the result.\ndisplay('Inverted join:', inverted_joined)\n```\n\nThe output should look something like: \n\n```\nImage LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140403 (17 bands)\nImage LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140419 (17 bands)\n```\n\nThe inverted join contains the images from April 3 and April 19, indicating the images\nthat are present in the `primary` collection but not in the\n`secondary` collection."]]