ee.FeatureCollection.reduceToImage
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tạo hình ảnh từ một tập hợp đối tượng bằng cách áp dụng một hàm rút gọn cho các thuộc tính đã chọn của tất cả đối tượng giao nhau với mỗi pixel.
Cách sử dụng | Giá trị trả về |
---|
FeatureCollection.reduceToImage(properties, reducer) | Hình ảnh |
Đối số | Loại | Thông tin chi tiết |
---|
this: collection | FeatureCollection | Tập hợp đối tượng cần giao với từng pixel đầu ra. |
properties | Danh sách | Các thuộc tính để chọn từ mỗi đối tượng và truyền vào hàm giảm. |
reducer | Bộ giảm tốc | Một Reducer để kết hợp các thuộc tính của từng đối tượng giao nhau thành kết quả cuối cùng để lưu trữ trong pixel. |
Ví dụ
Trình soạn thảo mã (JavaScript)
// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
.filter('country_lg == "Belgium"');
// Create an image from features; pixel values are determined from reduction of
// property values of the features intersecting each pixel.
var image = fc.reduceToImage({
properties: ['gwh_estimt'],
reducer: ee.Reducer.sum()
});
// The goal is to sum the electricity generated in 2015 for the power plants
// intersecting 10 km cells and view the result as a map layer.
// ee.FeatureCollection.reduceToImage does not allow the image projection to be
// set because it is waiting on downstream functions that include "crs",
// "scale", and "crsTransform" parameters to define it (e.g., Export.image.*).
// Here, we'll force the projection with ee.Image.reproject so the result can be
// viewed in the map. Note that using small scales with reproject while viewing
// large regions breaks the features that make Earth Engine fast and may result
// in poor performance and/or errors.
image = image.reproject('EPSG:3035', null, 10000);
// Display the image on the map.
Map.setCenter(4.3376, 50.947, 8);
Map.setLocked(true);
Map.addLayer(
image.updateMask(image.gt(0)),
{min: 0, max: 2000, palette: ['yellow', 'orange', 'red']},
'Total estimated annual electricity generation, 2015');
Map.addLayer(fc, null, 'Belgian power plants');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
cho quá trình phát triển tương tác.
import ee
import geemap.core as geemap
Colab (Python)
# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
'country_lg == "Belgium"'
)
# Create an image from features pixel values are determined from reduction of
# property values of the features intersecting each pixel.
image = fc.reduceToImage(properties=['gwh_estimt'], reducer=ee.Reducer.sum())
# The goal is to sum the electricity generated in 2015 for the power plants
# intersecting 10 km cells and view the result as a map layer.
# ee.FeatureCollection.reduceToImage does not allow the image projection to be
# set because it is waiting on downstream functions that include "crs",
# "scale", and "crsTransform" parameters to define it (e.g., Export.image.*).
# Here, we'll force the projection with ee.Image.reproject so the result can be
# viewed in the map. Note that using small scales with reproject while viewing
# large regions breaks the features that make Earth Engine fast and may result
# in poor performance and/or errors.
image = image.reproject('EPSG:3035', None, 10000)
# Display the image on the map.
m = geemap.Map()
m.set_center(4.3376, 50.947, 8)
m.add_layer(
image.updateMask(image.gt(0)),
{'min': 0, 'max': 2000, 'palette': ['yellow', 'orange', 'red']},
'Total estimated annual electricity generation, 2015',
)
m.add_layer(fc, None, 'Belgian power plants')
m
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003ereduceToImage\u003c/code\u003e creates an image from a FeatureCollection by applying a reducer to feature properties within each pixel.\u003c/p\u003e\n"],["\u003cp\u003eThe reducer combines the properties of features intersecting a pixel into a single pixel value in the output image.\u003c/p\u003e\n"],["\u003cp\u003eYou must specify the properties to include and the reducer to use when calling \u003ccode\u003ereduceToImage\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eOutput image projection is determined by subsequent operations like \u003ccode\u003ereproject\u003c/code\u003e or \u003ccode\u003eExport\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# ee.FeatureCollection.reduceToImage\n\nCreates an image from a feature collection by applying a reducer over the selected properties of all the features that intersect each pixel.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------------------------------------------|---------|\n| FeatureCollection.reduceToImage`(properties, reducer)` | Image |\n\n| Argument | Type | Details |\n|--------------------|-------------------|-------------------------------------------------------------------------------------------------------------|\n| this: `collection` | FeatureCollection | Feature collection to intersect with each output pixel. |\n| `properties` | List | Properties to select from each feature and pass into the reducer. |\n| `reducer` | Reducer | A Reducer to combine the properties of each intersecting feature into a final result to store in the pixel. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// FeatureCollection of power plants in Belgium.\nvar fc = ee.FeatureCollection('WRI/GPPD/power_plants')\n .filter('country_lg == \"Belgium\"');\n\n// Create an image from features; pixel values are determined from reduction of\n// property values of the features intersecting each pixel.\nvar image = fc.reduceToImage({\n properties: ['gwh_estimt'],\n reducer: ee.Reducer.sum()\n});\n\n// The goal is to sum the electricity generated in 2015 for the power plants\n// intersecting 10 km cells and view the result as a map layer.\n// ee.FeatureCollection.reduceToImage does not allow the image projection to be\n// set because it is waiting on downstream functions that include \"crs\",\n// \"scale\", and \"crsTransform\" parameters to define it (e.g., Export.image.*).\n// Here, we'll force the projection with ee.Image.reproject so the result can be\n// viewed in the map. Note that using small scales with reproject while viewing\n// large regions breaks the features that make Earth Engine fast and may result\n// in poor performance and/or errors.\nimage = image.reproject('EPSG:3035', null, 10000);\n\n// Display the image on the map.\nMap.setCenter(4.3376, 50.947, 8);\nMap.setLocked(true);\nMap.addLayer(\n image.updateMask(image.gt(0)),\n {min: 0, max: 2000, palette: ['yellow', 'orange', 'red']},\n 'Total estimated annual electricity generation, 2015');\nMap.addLayer(fc, null, 'Belgian power plants');\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# FeatureCollection of power plants in Belgium.\nfc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(\n 'country_lg == \"Belgium\"'\n)\n\n# Create an image from features pixel values are determined from reduction of\n# property values of the features intersecting each pixel.\nimage = fc.reduceToImage(properties=['gwh_estimt'], reducer=ee.Reducer.sum())\n\n# The goal is to sum the electricity generated in 2015 for the power plants\n# intersecting 10 km cells and view the result as a map layer.\n# ee.FeatureCollection.reduceToImage does not allow the image projection to be\n# set because it is waiting on downstream functions that include \"crs\",\n# \"scale\", and \"crsTransform\" parameters to define it (e.g., Export.image.*).\n# Here, we'll force the projection with ee.Image.reproject so the result can be\n# viewed in the map. Note that using small scales with reproject while viewing\n# large regions breaks the features that make Earth Engine fast and may result\n# in poor performance and/or errors.\nimage = image.reproject('EPSG:3035', None, 10000)\n\n# Display the image on the map.\nm = geemap.Map()\nm.set_center(4.3376, 50.947, 8)\nm.add_layer(\n image.updateMask(image.gt(0)),\n {'min': 0, 'max': 2000, 'palette': ['yellow', 'orange', 'red']},\n 'Total estimated annual electricity generation, 2015',\n)\nm.add_layer(fc, None, 'Belgian power plants')\nm\n```"]]