Earth Engine의 Feature
는 GeoJSON 지형지물로 정의됩니다. 구체적으로 Feature
는 Geometry
객체 (또는 null)를 저장하는 geometry
속성과 다른 속성의 사전을 저장하는 properties
속성이 있는 객체입니다.
Feature 객체 만들기
Feature
를 만들려면 생성자에 Geometry
및 기타 속성 사전 (선택사항)을 제공합니다. 예를 들면 다음과 같습니다.
코드 편집기 (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
도 검사 및 시각화를 위해 인쇄되거나 지도에 추가될 수 있습니다.
코드 편집기 (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
에는 Geometry
가 없어도 되며 속성 사전을 래핑할 수도 있습니다. 예를 들면 다음과 같습니다.
코드 편집기 (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
메서드도 기본 Geometry
를 가져오고, 작업을 적용하고, 결과를 새 기본 Geometry
로 설정하는 편의를 위해 Feature
에 있습니다.
결과는 메서드가 호출되는 Feature
의 다른 모든 속성을 유지합니다. Feature
의 도형이 아닌 속성을 가져오고 설정하는 메서드도 있습니다. 예를 들면 다음과 같습니다.
코드 편집기 (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()
는 기존 속성을 덮어씁니다.