یک Feature
در Earth Engine به عنوان ویژگی GeoJSON تعریف می شود. به طور خاص، Feature
یک شی با خاصیت geometry
است که یک شی Geometry
(یا تهی) را ذخیره می کند و یک ویژگی properties
است که فرهنگ لغت ویژگی های دیگر را ذخیره می کند.
ایجاد اشیاء ویژگی
برای ایجاد یک Feature
، یک Geometry
و (به صورت اختیاری) یک فرهنگ لغت از ویژگی های دیگر را در اختیار سازنده قرار دهید. به عنوان مثال:
ویرایشگر کد (جاوا اسکریپت)
// 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
کولب (پایتون)
# 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
ممکن است برای بررسی و تجسم به نقشه چاپ یا اضافه شود:
ویرایشگر کد (جاوا اسکریپت)
print(polyFeature); Map.addLayer(polyFeature, {}, 'feature');
import ee import geemap.core as geemap
کولب (پایتون)
display(poly_feature) m = geemap.Map() m.add_layer(poly_feature, {}, 'feature') display(m)
یک Feature
نیازی به Geometry
ندارد و ممکن است به سادگی یک فرهنگ لغت از ویژگی ها را بپیچد. به عنوان مثال:
ویرایشگر کد (جاوا اسکریپت)
// 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
کولب (پایتون)
# 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()
). برای جزئیات بیشتر به مجموعه ویژگی ها و وارد کردن داده های جدول یا راهنمای صادرات مراجعه کنید.
هر Feature
دارای یک Geometry
اولیه است که در ویژگی geometry
ذخیره شده است. هندسه های اضافی ممکن است در ویژگی های دیگر ذخیره شوند. روشهای Geometry
مانند تقاطع و بافر نیز در Feature
بهعنوان سهولت برای گرفتن Geometry
اولیه، اعمال عملیات و تنظیم نتیجه به عنوان Geometry
اولیه جدید وجود دارد. نتیجه تمام خصوصیات دیگر Feature
را که متد بر اساس آن فراخوانی شده است حفظ می کند. همچنین روش هایی برای دریافت و تنظیم ویژگی های غیر هندسی Feature
وجود دارد. به عنوان مثال:
ویرایشگر کد (جاوا اسکریپت)
// 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
کولب (پایتون)
# 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()
ویژگی های موجود را بازنویسی می کند.