기능 개요

Earth Engine의 Feature는 GeoJSON 지형지물로 정의됩니다. 구체적으로 FeatureGeometry 객체 (또는 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'});

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

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');

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

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);

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

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);

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

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()는 기존 속성을 덮어씁니다.