公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.clip
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将图片裁剪为几何图形或要素。
输出波段与输入波段完全对应,只是几何图形未覆盖的数据会被遮盖。输出图片会保留输入图片的元数据。
使用 clipToCollection 将图片裁剪为 FeatureCollection。
返回剪裁后的图片。
用法 | 返回 |
---|
Image.clip(geometry) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:image | 图片 | Image 实例。 |
geometry | Feature|Geometry|Object | 要剪裁到的几何图形或地图项。 |
示例
代码编辑器 (JavaScript)
// A digital elevation model.
var dem = ee.Image('NASA/NASADEM_HGT/001');
var demVis = {bands: 'elevation', min: 0, max: 1500};
// Clip the DEM by a polygon geometry.
var geomPoly = ee.Geometry.BBox(-121.55, 39.01, -120.57, 39.38);
var demClip = dem.clip(geomPoly);
print('Clipped image retains metadata and band names', demClip);
Map.setCenter(-121.12, 38.13, 8);
Map.addLayer(demClip, demVis, 'Polygon clip');
Map.addLayer(geomPoly, {color: 'green'}, 'Polygon geometry', false);
// Clip the DEM by a line geometry.
var geomLine = ee.Geometry.LinearRing(
[[-121.19, 38.10], [-120.53, 38.54], [-120.22, 37.83], [-121.19, 38.10]]);
Map.addLayer(dem.clip(geomLine), demVis, 'Line clip');
Map.addLayer(geomLine, {color: 'orange'}, 'Line geometry', false);
// Images have geometry; clip the dem image by the geometry of an S2 image.
var s2Img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
var geomS2Img = s2Img.geometry();
Map.addLayer(dem.clip(geomS2Img), demVis, 'Image geometry clip');
Map.addLayer(geomS2Img, {color: 'blue'}, 'Image geometry', false);
// Don't use ee.Image.clip prior to ee.Image.regionReduction, the "geometry"
// parameter handles it more efficiently.
var zonalMax = dem.select('elevation').reduceRegion({
reducer: ee.Reducer.max(),
geometry: geomPoly
});
print('Max elevation (m)', zonalMax.get('elevation'));
// Don't use ee.Image.clip to clip an image by a FeatureCollection, use
// ee.Image.clipToCollection(collection).
var watersheds = ee.FeatureCollection('USGS/WBD/2017/HUC10')
.filterBounds(ee.Geometry.Point(-122.754, 38.606).buffer(2e4));
Map.addLayer(dem.clipToCollection(watersheds), demVis, 'Watersheds clip');
Map.addLayer(watersheds, {color: 'red'}, 'Watersheds', false);
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# A digital elevation model.
dem = ee.Image('NASA/NASADEM_HGT/001')
dem_vis = {'bands': 'elevation', 'min': 0, 'max': 1500}
# Clip the DEM by a polygon geometry.
geom_poly = ee.Geometry.BBox(-121.55, 39.01, -120.57, 39.38)
dem_clip = dem.clip(geom_poly)
display('Clipped image retains metadata and band names', dem_clip)
m = geemap.Map()
m.set_center(-121.12, 38.13, 8)
m.add_layer(dem_clip, dem_vis, 'Polygon clip')
m.add_layer(geom_poly, {'color': 'green'}, 'Polygon geometry', False)
# Clip the DEM by a line geometry.
geom_line = ee.Geometry.LinearRing(
[[-121.19, 38.10], [-120.53, 38.54], [-120.22, 37.83], [-121.19, 38.10]]
)
m.add_layer(dem.clip(geom_line), dem_vis, 'Line clip')
m.add_layer(geom_line, {'color': 'orange'}, 'Line geometry', False)
# Images have geometry clip the dem image by the geometry of an S2 image.
s_2_img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
geom_s_2_img = s_2_img.geometry()
m.add_layer(dem.clip(geom_s_2_img), dem_vis, 'Image geometry clip')
m.add_layer(geom_s_2_img, {'color': 'blue'}, 'Image geometry', False)
# Don't use ee.Image.clip prior to ee.Image.regionReduction, the "geometry"
# parameter handles it more efficiently.
zonal_max = dem.select('elevation').reduceRegion(
reducer=ee.Reducer.max(), geometry=geom_poly
)
display('Max elevation (m)', zonal_max.get('elevation'))
# Don't use ee.Image.clip to clip an image by a FeatureCollection, use
# ee.Image.clipToCollection(collection).
watersheds = ee.FeatureCollection('USGS/WBD/2017/HUC10').filterBounds(
ee.Geometry.Point(-122.754, 38.606).buffer(2e4)
)
m.add_layer(dem.clipToCollection(watersheds), dem_vis, 'Watersheds clip')
m.add_layer(watersheds, {'color': 'red'}, 'Watersheds', False)
m
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[null,null,["最后更新时间 (UTC):2025-07-29。"],[[["\u003cp\u003e\u003ccode\u003eImage.clip()\u003c/code\u003e masks an image by a Geometry or Feature, retaining the input image's metadata and bands within the clipped area.\u003c/p\u003e\n"],["\u003cp\u003eThe output of \u003ccode\u003eImage.clip()\u003c/code\u003e is an Image with the same bands as the input, but with data outside the clip geometry masked.\u003c/p\u003e\n"],["\u003cp\u003eWhen clipping to a FeatureCollection, use \u003ccode\u003eclipToCollection()\u003c/code\u003e instead of \u003ccode\u003eImage.clip()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor \u003ccode\u003eregionReduction\u003c/code\u003e operations, specifying the geometry directly in the \u003ccode\u003ereduceRegion\u003c/code\u003e call is more efficient than pre-clipping the image.\u003c/p\u003e\n"]]],[],null,["# ee.Image.clip\n\n\u003cbr /\u003e\n\nClips an image to a Geometry or Feature.\n\n\u003cbr /\u003e\n\nThe output bands correspond exactly to the input bands, except data not covered by the geometry is masked. The output image retains the metadata of the input image.\n\nUse clipToCollection to clip an image to a FeatureCollection.\n\nReturns the clipped image.\n\n| Usage | Returns |\n|------------------------|---------|\n| Image.clip`(geometry)` | Image |\n\n| Argument | Type | Details |\n|---------------|---------------------------|-------------------------------------|\n| this: `image` | Image | The Image instance. |\n| `geometry` | Feature\\|Geometry\\|Object | The Geometry or Feature to clip to. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A digital elevation model.\nvar dem = ee.Image('NASA/NASADEM_HGT/001');\nvar demVis = {bands: 'elevation', min: 0, max: 1500};\n\n// Clip the DEM by a polygon geometry.\nvar geomPoly = ee.Geometry.BBox(-121.55, 39.01, -120.57, 39.38);\nvar demClip = dem.clip(geomPoly);\nprint('Clipped image retains metadata and band names', demClip);\nMap.setCenter(-121.12, 38.13, 8);\nMap.addLayer(demClip, demVis, 'Polygon clip');\nMap.addLayer(geomPoly, {color: 'green'}, 'Polygon geometry', false);\n\n// Clip the DEM by a line geometry.\nvar geomLine = ee.Geometry.LinearRing(\n [[-121.19, 38.10], [-120.53, 38.54], [-120.22, 37.83], [-121.19, 38.10]]);\nMap.addLayer(dem.clip(geomLine), demVis, 'Line clip');\nMap.addLayer(geomLine, {color: 'orange'}, 'Line geometry', false);\n\n// Images have geometry; clip the dem image by the geometry of an S2 image.\nvar s2Img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\nvar geomS2Img = s2Img.geometry();\nMap.addLayer(dem.clip(geomS2Img), demVis, 'Image geometry clip');\nMap.addLayer(geomS2Img, {color: 'blue'}, 'Image geometry', false);\n\n// Don't use ee.Image.clip prior to ee.Image.regionReduction, the \"geometry\"\n// parameter handles it more efficiently.\nvar zonalMax = dem.select('elevation').reduceRegion({\n reducer: ee.Reducer.max(),\n geometry: geomPoly\n});\nprint('Max elevation (m)', zonalMax.get('elevation'));\n\n// Don't use ee.Image.clip to clip an image by a FeatureCollection, use\n// ee.Image.clipToCollection(collection).\nvar watersheds = ee.FeatureCollection('USGS/WBD/2017/HUC10')\n .filterBounds(ee.Geometry.Point(-122.754, 38.606).buffer(2e4));\nMap.addLayer(dem.clipToCollection(watersheds), demVis, 'Watersheds clip');\nMap.addLayer(watersheds, {color: 'red'}, 'Watersheds', false);\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# A digital elevation model.\ndem = ee.Image('NASA/NASADEM_HGT/001')\ndem_vis = {'bands': 'elevation', 'min': 0, 'max': 1500}\n\n# Clip the DEM by a polygon geometry.\ngeom_poly = ee.Geometry.BBox(-121.55, 39.01, -120.57, 39.38)\ndem_clip = dem.clip(geom_poly)\ndisplay('Clipped image retains metadata and band names', dem_clip)\nm = geemap.Map()\nm.set_center(-121.12, 38.13, 8)\nm.add_layer(dem_clip, dem_vis, 'Polygon clip')\nm.add_layer(geom_poly, {'color': 'green'}, 'Polygon geometry', False)\n\n# Clip the DEM by a line geometry.\ngeom_line = ee.Geometry.LinearRing(\n [[-121.19, 38.10], [-120.53, 38.54], [-120.22, 37.83], [-121.19, 38.10]]\n)\nm.add_layer(dem.clip(geom_line), dem_vis, 'Line clip')\nm.add_layer(geom_line, {'color': 'orange'}, 'Line geometry', False)\n\n# Images have geometry clip the dem image by the geometry of an S2 image.\ns_2_img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')\ngeom_s_2_img = s_2_img.geometry()\nm.add_layer(dem.clip(geom_s_2_img), dem_vis, 'Image geometry clip')\nm.add_layer(geom_s_2_img, {'color': 'blue'}, 'Image geometry', False)\n\n# Don't use ee.Image.clip prior to ee.Image.regionReduction, the \"geometry\"\n# parameter handles it more efficiently.\nzonal_max = dem.select('elevation').reduceRegion(\n reducer=ee.Reducer.max(), geometry=geom_poly\n)\ndisplay('Max elevation (m)', zonal_max.get('elevation'))\n\n# Don't use ee.Image.clip to clip an image by a FeatureCollection, use\n# ee.Image.clipToCollection(collection).\nwatersheds = ee.FeatureCollection('USGS/WBD/2017/HUC10').filterBounds(\n ee.Geometry.Point(-122.754, 38.606).buffer(2e4)\n)\nm.add_layer(dem.clipToCollection(watersheds), dem_vis, 'Watersheds clip')\nm.add_layer(watersheds, {'color': 'red'}, 'Watersheds', False)\nm\n```"]]