Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Vector to raster conversion in Earth Engine is handled by the
featureCollection.reduceToImage() method. This method assigns pixels under
each feature the value of the specified property. This example uses the counties data
to create an image representing the land area of each county:
Specify a reducer to indicate how to aggregate properties of
overlapping features. In the previous example, since there is no overlap, an
ee.Reducer.first() is sufficient. As in this
example, pre-filter the data to eliminate nulls that can not be turned into an image.
The output should look something like Figure 1, which maps a color gradient to
county size. Like all image-outputting reducers in Earth Engine, the
scale is dynamically set by the output. In this case, the scale corresponds to the
zoom level in the Code Editor.
Figure 1. The result of reduceToImage() using the ‘ALAND’ (land area)
property of the 'TIGER/2018/Counties' FeatureCollection.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-02 UTC."],[[["\u003cp\u003eThe \u003ccode\u003efeatureCollection.reduceToImage()\u003c/code\u003e method in Earth Engine converts vector data (like county boundaries) into raster images by assigning pixel values based on a specified property (e.g., land area).\u003c/p\u003e\n"],["\u003cp\u003eTo avoid errors, it's crucial to pre-filter the data to remove any features with null values for the property being used to create the image.\u003c/p\u003e\n"],["\u003cp\u003eWhen dealing with overlapping features, you need to specify a reducer (like \u003ccode\u003eee.Reducer.first()\u003c/code\u003e) to determine how their properties are aggregated within each pixel.\u003c/p\u003e\n"],["\u003cp\u003eThe output image's scale is dynamic, adjusting to the current zoom level in the Code Editor, ensuring visual clarity at different scales.\u003c/p\u003e\n"],["\u003cp\u003eThis technique allows you to visualize feature properties geographically, using a color gradient to represent variations in values, as demonstrated in the county land area example.\u003c/p\u003e\n"]]],["Vector to raster conversion is achieved using `featureCollection.reduceToImage()`. This method assigns pixel values based on specified feature properties. The example converts US county data to an image representing land area. It filters out null values, applies `ee.Reducer.first()` to handle property aggregation, and sets color gradients based on county size. `geemap` is used for Python interactive development and displaying the output image, similar to the JavaScript example. The scale is dynamically set by the zoom level.\n"],null,["# Vector to Raster Conversion\n\nVector to raster conversion in Earth Engine is handled by the\n`featureCollection.reduceToImage()` method. This method assigns pixels under\neach feature the value of the specified property. This example uses the counties data\nto create an image representing the land area of each county:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a collection of US counties.\nvar counties = ee.FeatureCollection('TIGER/2018/Counties');\n\n// Make an image out of the land area attribute.\nvar landAreaImg = counties\n .filter(ee.Filter.notNull(['ALAND']))\n .reduceToImage({\n properties: ['ALAND'],\n reducer: ee.Reducer.first()\n});\n\n// Display the county land area image.\nMap.setCenter(-99.976, 40.38, 5);\nMap.addLayer(landAreaImg, {\n min: 3e8,\n max: 1.5e10,\n palette: ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C']\n});\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 collection of US counties.\ncounties = ee.FeatureCollection('TIGER/2018/Counties')\n\n# Make an image out of the land area attribute.\nland_area_img = counties.filter(ee.Filter.notNull(['ALAND'])).reduceToImage(\n properties=['ALAND'], reducer=ee.Reducer.first()\n)\n\n# Display the county land area image.\nm = geemap.Map()\nm.set_center(-99.976, 40.38, 5)\nm.add_layer(\n land_area_img,\n {\n 'min': 3e8,\n 'max': 1.5e10,\n 'palette': ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C'],\n },\n)\nm\n```\n\nSpecify a reducer to indicate how to aggregate properties of\noverlapping features. In the previous example, since there is no overlap, an\n`ee.Reducer.first()` is sufficient. As in [this\nexample](/earth-engine/guides/reducers_reduce_columns), pre-filter the data to eliminate nulls that can not be turned into an image.\nThe output should look something like Figure 1, which maps a color gradient to\ncounty size. Like all image-outputting reducers in Earth Engine, the\nscale is dynamically set by the output. In this case, the scale corresponds to the\nzoom level in the Code Editor.\nFigure 1. The result of `reduceToImage()` using the 'ALAND' (land area) property of the 'TIGER/2018/Counties' `FeatureCollection`."]]