סקירה כללית על התכונה

Feature ב-Earth Engine מוגדר כתכונה של GeoJSON. באופן ספציפי, Feature הוא אובייקט עם נכס geometry שמאחסן אובייקט Geometry (או null) ונכס properties שמאחסן מילון של נכסים אחרים.

יצירת אובייקטים מסוג Feature

כדי ליצור Feature, מספקים ל-constructor Geometry (אופציונלי) ומילון של מאפיינים אחרים. לדוגמה:

Code Editor‏ (JavaScript)

// Create an ee.Geometry.
var polygon = ee.Geometry.Polygon([
  [[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]
]);

// Create a Feature from the Geometry.
var polyFeature = ee.Feature(polygon, {foo: 42, bar: 'tart'});

הגדרת Python

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

import ee
import geemap.core as geemap

Colab (Python)

# Create an ee.Geometry.
polygon = ee.Geometry.Polygon(
    [[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]]
)

# Create a Feature from the Geometry.
poly_feature = ee.Feature(polygon, {'foo': 42, 'bar': 'tart'})

כמו Geometry, אפשר להדפיס את Feature או להוסיף אותו למפה לצורך בדיקה חזותית:

Code Editor‏ (JavaScript)

print(polyFeature);
Map.addLayer(polyFeature, {}, 'feature');

הגדרת Python

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

import ee
import geemap.core as geemap

Colab (Python)

display(poly_feature)
m = geemap.Map()
m.add_layer(poly_feature, {}, 'feature')
display(m)

לא חייב להיות ל-Feature Geometry, והוא יכול פשוט לעטוף מילון של נכסים. לדוגמה:

Code Editor‏ (JavaScript)

// Create a dictionary of properties, some of which may be computed values.
var dict = {foo: ee.Number(8).add(88), bar: 'nihao'};

// Create a null geometry feature with the dictionary of properties.
var nowhereFeature = ee.Feature(null, dict);

הגדרת Python

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

import ee
import geemap.core as geemap

Colab (Python)

# Create a dictionary of properties, some of which may be computed values.
dic = {'foo': ee.Number(8).add(88), 'bar': 'nihao'}

# Create a null geometry feature with the dictionary of properties.
nowhere_feature = ee.Feature(None, dic)

בדוגמה הזו, שימו לב שהמילון שסופק ל-Feature מכיל ערך מחושב. יצירת תכונות באופן הזה שימושית לייצוא חישובים ממושכים עם תוצאה מסוג Dictionary (למשל image.reduceRegion()). פרטים נוספים זמינים במדריכים בנושא FeatureCollections, ייבוא נתוני טבלה וייצוא.

לכל Feature יש Geometry ראשי אחד שמאוחסן בנכס geometry. ייתכן שגיאומטריות נוספות יישמרו בנכסים אחרים. שיטות Geometry כמו 'חיתוך' ו'מאגר' קיימות גם ב-Feature, כנוחות לקבלת Geometry הראשי, החלת הפעולה והגדרת התוצאה כ-Geometry הראשי החדש. התוצאה תכלול את כל שאר המאפיינים של Feature שאליו נקרא השיטה. יש גם שיטות לאחזור ולהגדרה של המאפיינים שאינם גיאומטריה של Feature. לדוגמה:

Code Editor‏ (JavaScript)

// Make a feature and set some properties.
var feature = ee.Feature(ee.Geometry.Point([-122.22599, 37.17605]))
  .set('genus', 'Sequoia').set('species', 'sempervirens');

// Get a property from the feature.
var species = feature.get('species');
print(species);

// Set a new property.
feature = feature.set('presence', 1);

// Overwrite the old properties with a new dictionary.
var newDict = {genus: 'Brachyramphus', species: 'marmoratus'};
var feature = feature.set(newDict);

// Check the result.
print(feature);

הגדרת Python

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

import ee
import geemap.core as geemap

Colab (Python)

# Make a feature and set some properties.
feature = (
    ee.Feature(ee.Geometry.Point([-122.22599, 37.17605]))
    .set('genus', 'Sequoia')
    .set('species', 'sempervirens')
)

# Get a property from the feature.
species = feature.get('species')
display(species)

# Set a new property.
feature = feature.set('presence', 1)

# Overwrite the old properties with a new dictionary.
new_dic = {'genus': 'Brachyramphus', 'species': 'marmoratus'}
feature = feature.set(new_dic)

# Check the result.
display(feature)

בדוגמה הקודמת, חשוב לשים לב שאפשר להגדיר מאפיינים באמצעות צמד מפתח/ערך או באמצעות מילון. חשוב גם לזכור שהשפעת feature.set() גוברת על הגדרת המאפיינים הקיימים.