Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
ee.Image.clip
Stay organized with collections
Save and categorize content based on your preferences.
Clips an image to a Geometry or Feature.
The 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.
Use clipToCollection to clip an image to a FeatureCollection.
Returns the clipped image.
Usage | Returns | Image.clip(geometry) | Image |
Argument | Type | Details | this: image | Image | The Image instance. |
geometry | Feature|Geometry|Object | The Geometry or Feature to clip to. |
Examples
Code Editor (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 setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
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
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["\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```"]]