[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003e\u003ccode\u003eimage.reduceToVectors()\u003c/code\u003e converts raster data (\u003ccode\u003eImage\u003c/code\u003e) to vector data (\u003ccode\u003eFeatureCollection\u003c/code\u003e) in Earth Engine.\u003c/p\u003e\n"],["\u003cp\u003eThis function creates vector polygons by grouping connected pixels with similar values.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egeometry\u003c/code\u003e, \u003ccode\u003escale\u003c/code\u003e, and \u003ccode\u003ecrs\u003c/code\u003e parameters should be specified for optimal results.\u003c/p\u003e\n"],["\u003cp\u003eOutput vectors contain properties based on the input image and a specified reducer (e.g., mean).\u003c/p\u003e\n"],["\u003cp\u003eThe example demonstrates using \u003ccode\u003ereduceToVectors()\u003c/code\u003e to create vector zones from a nightlights image of Japan based on light intensity thresholds.\u003c/p\u003e\n"]]],[],null,["# Raster to Vector Conversion\n\nTo convert from an `Image` (raster) to a `FeatureCollection`\n(vector) data type, use `image.reduceToVectors()`. This is the primary\nmechanism for vectorization in Earth Engine, and can be useful for generating regions\nfor input to other types of reducer. The `reduceToVectors()` method\ncreates polygon edges (optionally centroids or bounding boxes instead) at the boundary of\nhomogeneous groups of connected pixels.\n\nFor example, consider a 2012 nightlights image of Japan. Let the nightlights digital\nnumber serve as a proxy for development intensity. Define zones using arbitrary thresholds\non the nightlights, combine the zones into a single-band image, vectorize the zones using\n`reduceToVectors()`:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Japan boundary from the Large Scale International Boundary dataset.\nvar japan = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')\n .filter(ee.Filter.eq('country_na', 'Japan'));\n\n// Load a 2012 nightlights image, clipped to the Japan border.\nvar nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')\n .select('stable_lights')\n .clipToCollection(japan);\n\n// Define arbitrary thresholds on the 6-bit nightlights image.\nvar zones = nl2012.gt(30).add(nl2012.gt(55)).add(nl2012.gt(62));\nzones = zones.updateMask(zones.neq(0));\n\n// Convert the zones of the thresholded nightlights to vectors.\nvar vectors = zones.addBands(nl2012).reduceToVectors({\n geometry: japan,\n crs: nl2012.projection(),\n scale: 1000,\n geometryType: 'polygon',\n eightConnected: false,\n labelProperty: 'zone',\n reducer: ee.Reducer.mean()\n});\n\n// Display the thresholds.\nMap.setCenter(139.6225, 35.712, 9);\nMap.addLayer(zones, {min: 1, max: 3, palette: ['0000FF', '00FF00', 'FF0000']}, 'raster');\n\n// Make a display image for the vectors, add it to the map.\nvar display = ee.Image(0).updateMask(0).paint(vectors, '000000', 3);\nMap.addLayer(display, {palette: '000000'}, 'vectors');\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# Load a Japan boundary from the Large Scale International Boundary dataset.\njapan = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(\n ee.Filter.eq('country_na', 'Japan')\n)\n\n# Load a 2012 nightlights image, clipped to the Japan border.\nnl_2012 = (\n ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')\n .select('stable_lights')\n .clipToCollection(japan)\n)\n\n# Define arbitrary thresholds on the 6-bit nightlights image.\nzones = nl_2012.gt(30).add(nl_2012.gt(55)).add(nl_2012.gt(62))\nzones = zones.updateMask(zones.neq(0))\n\n# Convert the zones of the thresholded nightlights to vectors.\nvectors = zones.addBands(nl_2012).reduceToVectors(\n geometry=japan,\n crs=nl_2012.projection(),\n scale=1000,\n geometryType='polygon',\n eightConnected=False,\n labelProperty='zone',\n reducer=ee.Reducer.mean(),\n)\n\n# Display the thresholds.\nm = geemap.Map()\nm.set_center(139.6225, 35.712, 9)\nm.add_layer(\n zones,\n {'min': 1, 'max': 3, 'palette': ['0000FF', '00FF00', 'FF0000']},\n 'raster',\n)\n\n# Make a display image for the vectors, add it to the map.\ndisplay_image = ee.Image(0).updateMask(0).paint(vectors, '000000', 3)\nm.add_layer(display_image, {'palette': '000000'}, 'vectors')\nm\n```\n\nNote that the first band in the input is used to identify homogeneous regions and the\nremaining bands are reduced according to the provided reducer, the output of which is\nadded as a property to the resultant vectors. The `geometry` parameter\nspecifies the extent over which the vectors should be created. In general, it is good\npractice to specify a minimal zone over which to create vectors. It is also good practice\nto specify the `scale` and `crs` to avoid ambiguity. The output type\nis `'polygon'` where the polygons are formed from homogeneous zones of\nfour-connected neighbors (i.e. `eightConnected` is false). The last two\nparameters, `labelProperty` and `reducer`, specify that the output\npolygons should receive a property with the zone label and the mean of the nightlights\nband(s), respectively.\n\nThe mapped result should look something like the Tokyo area shown in Figure 1.\nInspection of the output polygons indicates that each polygon has a property storing the\nlabel of the zone ({1, 2, 3}) and the mean of the nightlights band, since the mean\nreducer is specified.\nFigure 1. Zones of nightlights in the Tokyo, Japan area. Vector boundaries are displayed in black."]]