המרה של וקטור לרסטר

ההמרה של וקטור לרשת ב-Earth Engine מתבצעת באמצעות השיטה featureCollection.reduceToImage(). השיטה הזו מקצה פיקסלים מתחת לכל מאפיין עם הערך של המאפיין שצוין. בדוגמה הזו נעשה שימוש בנתוני המחוזות כדי ליצור תמונה שמייצגת את שטח היבשה של כל מחוז:

Code Editor‏ (JavaScript)

// Load a collection of US counties.
var counties = ee.FeatureCollection('TIGER/2018/Counties');

// Make an image out of the land area attribute.
var landAreaImg = counties
  .filter(ee.Filter.notNull(['ALAND']))
  .reduceToImage({
    properties: ['ALAND'],
    reducer: ee.Reducer.first()
});

// Display the county land area image.
Map.setCenter(-99.976, 40.38, 5);
Map.addLayer(landAreaImg, {
  min: 3e8,
  max: 1.5e10,
  palette: ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C']
});

הגדרת Python

בדף סביבת Python מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load a collection of US counties.
counties = ee.FeatureCollection('TIGER/2018/Counties')

# Make an image out of the land area attribute.
land_area_img = counties.filter(ee.Filter.notNull(['ALAND'])).reduceToImage(
    properties=['ALAND'], reducer=ee.Reducer.first()
)

# Display the county land area image.
m = geemap.Map()
m.set_center(-99.976, 40.38, 5)
m.add_layer(
    land_area_img,
    {
        'min': 3e8,
        'max': 1.5e10,
        'palette': ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C'],
    },
)
m

מציינים מחולל (reducer) כדי לציין איך לקבץ מאפיינים של תכונות חופפות. בדוגמה הקודמת, מכיוון שאין חפיפה, מספיק להשתמש ב-ee.Reducer.first(). כמו בדוגמה הזו, מסננים מראש את הנתונים כדי להסיר ערכים null שלא ניתן להפוך לתמונה. הפלט אמור להיראות בערך כמו באיור 1, שבו מיפוי של שיפוע צבע לפי גודל המחוז. כמו כל הפונקציות להקטנת נתונים שמפיקות תמונות ב-Earth Engine, ההיקף מוגדר באופן דינמי לפי הפלט. במקרה כזה, קנה המידה תואם לרמת הזום בעורך הקוד.

הפלט של reduceToImage
איור 1. התוצאה של reduceToImage() באמצעות המאפיין 'ALAND' (שטח יבשתי) של FeatureCollection ב-'TIGER/2018/Counties'.