Earth Engine'da Feature
, GeoJSON özelliği olarak tanımlanır. Daha açık belirtmek gerekirse, Feature
, Geometry
nesnesi (veya null) depolayan bir geometry
özelliğine ve diğer özelliklerin sözlüğünü depolayan bir properties
özelliğine sahip bir nesnedir.
Özellik nesneleri oluşturma
Feature
oluşturmak için oluşturucuya bir Geometry
ve (isteğe bağlı olarak) diğer özelliklerin sözlüğünü sağlayın. Örneğin:
Kod Düzenleyici (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
'te olduğu gibi, Feature
da incelenip görselleştirilmesi için basılabilir veya haritaya eklenebilir:
Kod Düzenleyici (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)
Feature
'lerin Geometry
içermesi gerekmez ve bunlar yalnızca bir mülk sözlüğünü sarmalayabilir. Örneğin:
Kod Düzenleyici (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)
Bu örnekte, Feature
parametresine sağlanan sözlüğün hesaplanmış bir değer içerdiğini unutmayın. Bu şekilde özellik oluşturmak, uzun süren hesaplamaları Dictionary
sonucuyla (ör. image.reduceRegion()
) dışa aktarmak için kullanışlıdır. Ayrıntılar için FeatureCollections ve Tablo Verilerini İçe Aktarma veya Dışa Aktarma kılavuzlarına bakın.
Her Feature
, geometry
mülkünde depolanan bir birincil Geometry
'e sahiptir. Diğer mülklerde ek geometriler depolanabilir.
Birincil Geometry
'yi almak, işlemi uygulamak ve sonucu yeni birincil Geometry
olarak ayarlamak için Feature
'da kesişim ve arabellek gibi Geometry
yöntemleri de mevcuttur.
Sonuç, yöntemin çağrıldığı Feature
'nin diğer tüm özelliklerini korur. Feature
'nin geometri dışı özelliklerini alma ve ayarlama yöntemleri de vardır. Örneğin:
Kod Düzenleyici (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)
Önceki örnekte, özelliklerin anahtar/değer çifti veya sözlük ile ayarlanabileceğini unutmayın. Ayrıca, feature.set()
'ün mevcut özelliklerinin üzerine yazdığını unutmayın.