ee.Image.clipToCollection
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัดรูปภาพไปยัง FeatureCollection แบนด์เอาต์พุตจะสอดคล้องกับแบนด์อินพุตทุกประการ ยกเว้นข้อมูลที่ไม่ได้ครอบคลุมโดยรูปเรขาคณิตของฟีเจอร์อย่างน้อย 1 รายการจากคอลเล็กชันจะถูกมาสก์ รูปภาพเอาต์พุตจะยังคงมีข้อมูลเมตาของรูปภาพอินพุต
การใช้งาน | การคืนสินค้า |
---|
Image.clipToCollection(collection) | รูปภาพ |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
ดังนี้ input | รูปภาพ | รูปภาพที่จะตัด |
collection | วัตถุ | FeatureCollection ที่จะตัด |
ตัวอย่าง
โปรแกรมแก้ไขโค้ด (JavaScript)
// A digital elevation model.
var dem = ee.Image('NASA/NASADEM_HGT/001');
// A FeatureCollection defining Southeast Asia boundary.
var fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
.filter('wld_rgn == "SE Asia"');
// Clip the DEM by the Southeast Asia boundary FeatureCollection.
var demClip = dem.clipToCollection(fc);
print('Clipped image retains metadata and band names', demClip);
// Add layers to the map.
Map.setCenter(110.64, 9.16, 4);
Map.addLayer(dem, {bands: 'elevation', min: 0, max: 2500}, 'Original DEM');
Map.addLayer(fc, {color: 'blue'}, 'FeatureCollection');
Map.addLayer(demClip,
{bands: 'elevation', min: 0, max: 2500, palette: ['green', 'yellow', 'brown']},
'Clipped DEM');
การตั้งค่า 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')
# A FeatureCollection defining Southeast Asia boundary.
fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(
'wld_rgn == "SE Asia"'
)
# Clip the DEM by the Southeast Asia boundary FeatureCollection.
dem_clip = dem.clipToCollection(fc)
display('Clipped image retains metadata and band names', dem_clip)
# Add layers to the map.
m = geemap.Map()
m.set_center(110.64, 9.16, 4)
m.add_layer(dem, {'bands': 'elevation', 'min': 0, 'max': 2500}, 'Original DEM')
m.add_layer(fc, {'color': 'blue'}, 'FeatureCollection')
m.add_layer(
dem_clip,
{
'bands': 'elevation',
'min': 0,
'max': 2500,
'palette': ['green', 'yellow', 'brown'],
},
'Clipped DEM',
)
m
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eClips an image to the boundaries of a FeatureCollection, masking data outside the features.\u003c/p\u003e\n"],["\u003cp\u003eOutput image retains the original metadata and band structure of the input image.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eclipToCollection()\u003c/code\u003e takes an image and a FeatureCollection as input, returning a clipped image.\u003c/p\u003e\n"],["\u003cp\u003eUseful for focusing analysis on specific geographic regions defined by features.\u003c/p\u003e\n"]]],[],null,["# ee.Image.clipToCollection\n\nClips an image to a FeatureCollection. The output bands correspond exactly the input bands, except data not covered by the geometry of at least one feature from the collection is masked. The output image retains the metadata of the input image.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------------------------|---------|\n| Image.clipToCollection`(collection)` | Image |\n\n| Argument | Type | Details |\n|---------------|--------|-----------------------------------|\n| this: `input` | Image | The image to clip. |\n| `collection` | Object | The FeatureCollection 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');\n\n// A FeatureCollection defining Southeast Asia boundary.\nvar fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')\n .filter('wld_rgn == \"SE Asia\"');\n\n// Clip the DEM by the Southeast Asia boundary FeatureCollection.\nvar demClip = dem.clipToCollection(fc);\nprint('Clipped image retains metadata and band names', demClip);\n\n// Add layers to the map.\nMap.setCenter(110.64, 9.16, 4);\nMap.addLayer(dem, {bands: 'elevation', min: 0, max: 2500}, 'Original DEM');\nMap.addLayer(fc, {color: 'blue'}, 'FeatureCollection');\nMap.addLayer(demClip,\n {bands: 'elevation', min: 0, max: 2500, palette: ['green', 'yellow', 'brown']},\n 'Clipped DEM');\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')\n\n# A FeatureCollection defining Southeast Asia boundary.\nfc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(\n 'wld_rgn == \"SE Asia\"'\n)\n\n# Clip the DEM by the Southeast Asia boundary FeatureCollection.\ndem_clip = dem.clipToCollection(fc)\ndisplay('Clipped image retains metadata and band names', dem_clip)\n\n# Add layers to the map.\nm = geemap.Map()\nm.set_center(110.64, 9.16, 4)\nm.add_layer(dem, {'bands': 'elevation', 'min': 0, 'max': 2500}, 'Original DEM')\nm.add_layer(fc, {'color': 'blue'}, 'FeatureCollection')\nm.add_layer(\n dem_clip,\n {\n 'bands': 'elevation',\n 'min': 0,\n 'max': 2500,\n 'palette': ['green', 'yellow', 'brown'],\n },\n 'Clipped DEM',\n)\nm\n```"]]