ee.Image.sampleRegions
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Convertit chaque pixel d'une image (à une échelle donnée) qui croise une ou plusieurs régions en Feature, et les renvoie sous forme de FeatureCollection. Chaque entité de sortie aura une propriété par bande de l'image d'entrée, ainsi que toutes les propriétés spécifiées copiées à partir de l'entité d'entrée.
Notez que les géométries seront alignées sur les centres des pixels.
Utilisation | Renvoie |
---|
Image.sampleRegions(collection, properties, scale, projection, tileScale, geometries) | FeatureCollection |
Argument | Type | Détails |
---|
ceci : image | Image | Image à échantillonner. |
collection | FeatureCollection | Régions à échantillonner. |
properties | Liste, valeur par défaut : null | Liste des propriétés à copier à partir de chaque caractéristique d'entrée. Valeur par défaut : toutes les propriétés non système. |
scale | Float, valeur par défaut : null | Échelle nominale en mètres de la projection à échantillonner. Si aucune valeur n'est spécifiée, l'échelle de la première bande de l'image est utilisée. |
projection | Projection, valeur par défaut : null | Projection dans laquelle échantillonner. Si aucune projection n'est spécifiée, celle de la première bande de l'image est utilisée. Si elle est spécifiée en plus de la mise à l'échelle, elle est remise à l'échelle spécifiée. |
tileScale | Float, valeur par défaut : 1 | Facteur de scaling utilisé pour réduire la taille des tuiles d'agrégation. Si vous utilisez un tileScale plus grand (par exemple, 2 ou 4) peut permettre d'effectuer des calculs qui manquent de mémoire avec la valeur par défaut. |
geometries | Booléen, valeur par défaut : false | Si la valeur est "true", les résultats incluront une géométrie de point par pixel échantillonné. Sinon, les géométries seront omises (ce qui permet d'économiser de la mémoire). |
Exemples
Éditeur de code (JavaScript)
// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
Map.setCenter(-122.503881, 37.765588, 18);
Map.addLayer(img, {bands: ['B11', 'B8', 'B3'], min: 100, max: 4500}, 'img');
// A feature collection with two polygon regions each intersecting 36
// pixels at 10 m scale.
var fcPolygon = ee.FeatureCollection([
ee.Feature(ee.Geometry.Rectangle(
-122.50620929, 37.76502806, -122.50552264, 37.76556663), {id: 0}),
ee.Feature(ee.Geometry.Rectangle(
-122.50530270, 37.76565568, -122.50460533, 37.76619425), {id: 1})
]);
Map.addLayer(fcPolygon, {color: 'yellow'}, 'fcPolygon');
var fcPolygonSamp = img.sampleRegions({
collection: fcPolygon,
scale: 10,
geometries: true
});
// Note that 7 pixels are missing from the sample. If a pixel contains a masked
// band value it will be excluded from the sample. In this case, the TCI_B band
// is masked for each unsampled pixel.
print('A feature per pixel (at given scale) in each region', fcPolygonSamp);
Map.addLayer(fcPolygonSamp, {color: 'purple'}, 'fcPolygonSamp');
// A feature collection with two points intersecting two different pixels.
// This example is included to show the behavior for point geometries. In
// practice, if the feature collection is all points, ee.Image.reduceRegions
// should be used instead to save memory.
var fcPoint = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {id: 0}),
ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {id: 1})
]);
Map.addLayer(fcPoint, {color: 'cyan'}, 'fcPoint');
var fcPointSamp = img.sampleRegions({
collection: fcPoint,
scale: 10
});
print('A feature per point', fcPointSamp);
Configuration de Python
Consultez la page
Environnement Python pour en savoir plus sur l'API Python et sur l'utilisation de geemap
pour le développement interactif.
import ee
import geemap.core as geemap
Colab (Python)
# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
m = geemap.Map()
m.set_center(-122.503881, 37.765588, 18)
m.add_layer(
img, {'bands': ['B11', 'B8', 'B3'], 'min': 100, 'max': 4500}, 'img'
)
display(m)
# A feature collection with two polygon regions each intersecting 36
# pixels at 10 m scale.
fc_polygon = ee.FeatureCollection([
ee.Feature(
ee.Geometry.Rectangle(
-122.50620929, 37.76502806, -122.50552264, 37.76556663
),
{'id': 0},
),
ee.Feature(
ee.Geometry.Rectangle(
-122.50530270, 37.76565568, -122.50460533, 37.76619425
),
{'id': 1},
),
])
m.add_layer(fc_polygon, {'color': 'yellow'}, 'fc_polygon')
fc_polygon_samp = img.sampleRegions(
collection=fc_polygon, scale=10, geometries=True
)
# Note that 7 pixels are missing from the sample. If a pixel contains a masked
# band value it will be excluded from the sample. In this case, the TCI_B band
# is masked for each unsampled pixel.
display('A feature per pixel (at given scale) in each region', fc_polygon_samp)
m.add_layer(fc_polygon_samp, {'color': 'purple'}, 'fc_polygon_samp')
# A feature collection with two points intersecting two different pixels.
# This example is included to show the behavior for point geometries. In
# practice, if the feature collection is all points, ee.Image.reduceRegions
# should be used instead to save memory.
fc_point = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {'id': 0}),
ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {'id': 1}),
])
m.add_layer(fc_point, {'color': 'cyan'}, 'fc_point')
fc_point_samp = img.sampleRegions(collection=fc_point, scale=10)
display('A feature per point', fc_point_samp)
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 2025/07/26 (UTC)."],[[["\u003cp\u003e\u003ccode\u003eImage.sampleRegions\u003c/code\u003e extracts pixel values from an image within specified regions, returning them as a FeatureCollection.\u003c/p\u003e\n"],["\u003cp\u003eEach output feature contains the band values of the input image for each sampled pixel, along with properties from the input features.\u003c/p\u003e\n"],["\u003cp\u003eGeometries are snapped to pixel centers, and you can control the sampling scale and projection.\u003c/p\u003e\n"],["\u003cp\u003eThe function provides options to include point geometries and adjust the tile scale for memory management.\u003c/p\u003e\n"],["\u003cp\u003eIf the input is a FeatureCollection of points, \u003ccode\u003eee.Image.reduceRegions\u003c/code\u003e is generally recommended for better memory efficiency.\u003c/p\u003e\n"]]],["The `Image.sampleRegions` method converts image pixels intersecting specified regions into a `FeatureCollection`. Each output feature contains properties from the input image bands and any designated input feature properties. Geometries are snapped to pixel centers. The sampling scale and projection can be specified; otherwise, the image's first band defaults are used. Optionally, geometries of the sampled pixels can be included, and tile scaling can be used for memory management.\n"],null,["# ee.Image.sampleRegions\n\nConverts each pixel of an image (at a given scale) that intersects one or more regions to a Feature, returning them as a FeatureCollection. Each output feature will have one property per band of the input image, as well as any specified properties copied from the input feature.\n\n\u003cbr /\u003e\n\nNote that geometries will be snapped to pixel centers.\n\n| Usage | Returns |\n|-----------------------------------------------------------------------------------------------------------------|-------------------|\n| Image.sampleRegions`(collection, `*properties* `, `*scale* `, `*projection* `, `*tileScale* `, `*geometries*`)` | FeatureCollection |\n\n| Argument | Type | Details |\n|---------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | The image to sample. |\n| `collection` | FeatureCollection | The regions to sample over. |\n| `properties` | List, default: null | The list of properties to copy from each input feature. Defaults to all non-system properties. |\n| `scale` | Float, default: null | A nominal scale in meters of the projection to sample in. If unspecified, the scale of the image's first band is used. |\n| `projection` | Projection, default: null | The projection in which to sample. If unspecified, the projection of the image's first band is used. If specified in addition to scale, rescaled to the specified scale. |\n| `tileScale` | Float, default: 1 | A scaling factor used to reduce aggregation tile size; using a larger tileScale (e.g., 2 or 4) may enable computations that run out of memory with the default. |\n| `geometries` | Boolean, default: false | If true, the results will include a point geometry per sampled pixel. Otherwise, geometries will be omitted (saving memory). |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Sentinel-2 surface reflectance image.\nvar img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\nMap.setCenter(-122.503881, 37.765588, 18);\nMap.addLayer(img, {bands: ['B11', 'B8', 'B3'], min: 100, max: 4500}, 'img');\n\n// A feature collection with two polygon regions each intersecting 36\n// pixels at 10 m scale.\nvar fcPolygon = ee.FeatureCollection([\n ee.Feature(ee.Geometry.Rectangle(\n -122.50620929, 37.76502806, -122.50552264, 37.76556663), {id: 0}),\n ee.Feature(ee.Geometry.Rectangle(\n -122.50530270, 37.76565568, -122.50460533, 37.76619425), {id: 1})\n]);\nMap.addLayer(fcPolygon, {color: 'yellow'}, 'fcPolygon');\n\nvar fcPolygonSamp = img.sampleRegions({\n collection: fcPolygon,\n scale: 10,\n geometries: true\n});\n// Note that 7 pixels are missing from the sample. If a pixel contains a masked\n// band value it will be excluded from the sample. In this case, the TCI_B band\n// is masked for each unsampled pixel.\nprint('A feature per pixel (at given scale) in each region', fcPolygonSamp);\nMap.addLayer(fcPolygonSamp, {color: 'purple'}, 'fcPolygonSamp');\n\n// A feature collection with two points intersecting two different pixels.\n// This example is included to show the behavior for point geometries. In\n// practice, if the feature collection is all points, ee.Image.reduceRegions\n// should be used instead to save memory.\nvar fcPoint = ee.FeatureCollection([\n ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {id: 0}),\n ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {id: 1})\n]);\nMap.addLayer(fcPoint, {color: 'cyan'}, 'fcPoint');\n\nvar fcPointSamp = img.sampleRegions({\n collection: fcPoint,\n scale: 10\n});\nprint('A feature per point', fcPointSamp);\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 Sentinel-2 surface reflectance image.\nimg = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')\nm = geemap.Map()\nm.set_center(-122.503881, 37.765588, 18)\nm.add_layer(\n img, {'bands': ['B11', 'B8', 'B3'], 'min': 100, 'max': 4500}, 'img'\n)\ndisplay(m)\n\n# A feature collection with two polygon regions each intersecting 36\n# pixels at 10 m scale.\nfc_polygon = ee.FeatureCollection([\n ee.Feature(\n ee.Geometry.Rectangle(\n -122.50620929, 37.76502806, -122.50552264, 37.76556663\n ),\n {'id': 0},\n ),\n ee.Feature(\n ee.Geometry.Rectangle(\n -122.50530270, 37.76565568, -122.50460533, 37.76619425\n ),\n {'id': 1},\n ),\n])\nm.add_layer(fc_polygon, {'color': 'yellow'}, 'fc_polygon')\n\nfc_polygon_samp = img.sampleRegions(\n collection=fc_polygon, scale=10, geometries=True\n)\n# Note that 7 pixels are missing from the sample. If a pixel contains a masked\n# band value it will be excluded from the sample. In this case, the TCI_B band\n# is masked for each unsampled pixel.\ndisplay('A feature per pixel (at given scale) in each region', fc_polygon_samp)\nm.add_layer(fc_polygon_samp, {'color': 'purple'}, 'fc_polygon_samp')\n\n# A feature collection with two points intersecting two different pixels.\n# This example is included to show the behavior for point geometries. In\n# practice, if the feature collection is all points, ee.Image.reduceRegions\n# should be used instead to save memory.\nfc_point = ee.FeatureCollection([\n ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {'id': 0}),\n ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {'id': 1}),\n])\nm.add_layer(fc_point, {'color': 'cyan'}, 'fc_point')\n\nfc_point_samp = img.sampleRegions(collection=fc_point, scale=10)\ndisplay('A feature per point', fc_point_samp)\n```"]]