[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eClips and scales an image to the boundaries of a specified geometry.\u003c/p\u003e\n"],["\u003cp\u003eOffers flexible scaling options using \u003ccode\u003ewidth\u003c/code\u003e/\u003ccode\u003eheight\u003c/code\u003e, \u003ccode\u003emaxDimension\u003c/code\u003e, or \u003ccode\u003escale\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAccepts Geometry objects like polygons or bounding boxes for clipping.\u003c/p\u003e\n"],["\u003cp\u003eCan result in poor performance when using large or complex geometries.\u003c/p\u003e\n"],["\u003cp\u003ePreserves image metadata and band names after clipping and scaling.\u003c/p\u003e\n"]]],[],null,["# ee.Image.clipToBoundsAndScale\n\nClips an image to the bounds of a Geometry, and scales the clipped image to a particular size or scale.\n\n\u003cbr /\u003e\n\n| **Caution:** providing a large or complex collection as the `geometry` argument can result in poor performance. Collating the geometry of collections does not scale well; use the smallest collection (or geometry) that is required to achieve the desired outcome.\n\n| Usage | Returns |\n|----------------------------------------------------------------------------------------------------|---------|\n| Image.clipToBoundsAndScale`(`*geometry* `, `*width* `, `*height* `, `*maxDimension* `, `*scale*`)` | Image |\n\n| Argument | Type | Details |\n|----------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `input` | Image | The image to clip and scale. |\n| `geometry` | Geometry, default: null | The Geometry to clip the image to. The image will be clipped to the bounding box, in the image's projection, of this geometry. |\n| `width` | Integer, default: null | The width to scale the image to, in pixels. Must be provided along with \"height\". Exclusive with \"maxDimension\" and \"scale\". |\n| `height` | Integer, default: null | The height to scale the image to, in pixels. Must be provided along with \"width\". Exclusive with \"maxDimension\" and \"scale\". |\n| `maxDimension` | Integer, default: null | The maximum dimension to scale the image to, in pixels. Exclusive with \"width\", \"height\" and \"scale\". |\n| `scale` | Float, default: null | If scale is specified, then the projection is scaled by dividing the specified scale value by the nominal size of a meter in the image's projection. Exclusive with \"width\", \"height\", and \"maxDimension\". |\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: 2000};\nprint('DEM', dem);\nMap.setCenter(-121.38, 46.51, 8);\nMap.addLayer(dem, demVis, 'DEM');\n\n// Clip DEM by a single polygon geometry, specify width and height parameters.\nvar geom1 = ee.Geometry.BBox(-123.55, 46.61, -122.57, 46.98);\nvar demClip1 = dem.clipToBoundsAndScale({\n geometry: geom1,\n width: 20, // pixels\n height: 10 // pixels\n});\nprint('Clipped image retains metadata and band names', demClip1);\nMap.addLayer(demClip1, demVis, 'Single geometry clip (width, height)');\nMap.addLayer(geom1, {color: 'red'}, 'Single geometry (width, height)');\n\n// Clip DEM by a single polygon geometry, specify maxDimension parameter.\nvar geom2 = ee.Geometry.BBox(-120.79, 46.58, -120.16, 46.81);\nvar demClip2 = dem.clipToBoundsAndScale({\n geometry: geom2,\n maxDimension: 5, // pixels\n});\nMap.addLayer(demClip2, demVis, 'Single polygon clip (maxDimension)');\nMap.addLayer(geom2, {color: 'yellow'}, 'Single polygon (maxDimension)');\n\n// Clip DEM by a single polygon geometry, specify scale parameter.\nvar geom3 = ee.Geometry.BBox(-120.79, 46.18, -120.16, 46.41);\nvar demClip3 = dem.clipToBoundsAndScale({\n geometry: geom3,\n scale: 1e4, // meters\n});\nMap.addLayer(demClip3, demVis, 'Single polygon clip (scale)');\nMap.addLayer(geom3, {color: 'blue'}, 'Single polygon (scale)');\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': 2000}\ndisplay('DEM', dem)\nm = geemap.Map()\nm.set_center(-121.38, 46.51, 8)\nm.add_layer(dem, dem_vis, 'DEM')\n\n# Clip DEM by a single polygon geometry, specify width and height parameters.\ngeom_1 = ee.Geometry.BBox(-123.55, 46.61, -122.57, 46.98)\ndem_clip_1 = dem.clipToBoundsAndScale(geometry=geom_1, width=20, height=10)\ndisplay('Clipped image retains metadata and band names', dem_clip_1)\nm.add_layer(dem_clip_1, dem_vis, 'Single geometry clip (width, height)')\nm.add_layer(geom_1, {'color': 'red'}, 'Single geometry (width, height)')\n\n# Clip DEM by a single polygon geometry, specify maxDimension parameter.\ngeom_2 = ee.Geometry.BBox(-120.79, 46.58, -120.16, 46.81)\ndem_clip_2 = dem.clipToBoundsAndScale(geometry=geom_2, maxDimension=5)\nm.add_layer(dem_clip_2, dem_vis, 'Single polygon clip (maxDimension)')\nm.add_layer(geom_2, {'color': 'yellow'}, 'Single polygon (maxDimension)')\n\n# Clip DEM by a single polygon geometry, specify scale parameter.\ngeom_3 = ee.Geometry.BBox(-120.79, 46.18, -120.16, 46.41)\ndem_clip_3 = dem.clipToBoundsAndScale(geometry=geom_3, scale=1e4)\nm.add_layer(dem_clip_3, dem_vis, 'Single polygon clip (scale)')\nm.add_layer(geom_3, {'color': 'blue'}, 'Single polygon (scale)')\nm\n```"]]