Feature ב-Earth Engine מוגדר כ-GeoJSON Feature. באופן ספציפי,
Feature הוא אובייקט עם מאפיין geometry שמאחסן
אובייקט Geometry (או null) ומאפיין properties שמאחסן
מילון של מאפיינים אחרים.
יצירת אובייקטים של תכונות
כדי ליצור 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'});
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');
import ee import geemap.core as geemap
Colab (Python)
display(poly_feature) m = geemap.Map() m.add_layer(poly_feature, {}, 'feature') display(m)
לא חייב להיות Geometry ל-Feature, והוא יכול פשוט לעטוף מילון של מאפיינים. לדוגמה:
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);
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 שעליו
הופעלה ה-method. יש גם שיטות לקבלת ולהגדרת המאפיינים הלא-גיאומטריים של 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);
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()
מחליפה את המאפיינים הקיימים.