ภาพรวมของฟีเจอร์

Feature ใน Earth Engine หมายถึงองค์ประกอบ GeoJSON กล่าวโดยละเอียดคือ Feature คือออบเจ็กต์ที่มีพร็อพเพอร์ตี้ geometry ซึ่งจัดเก็บออบเจ็กต์ Geometry (หรือ Null) และพร็อพเพอร์ตี้ properties ซึ่งจัดเก็บพจนานุกรมของพร็อพเพอร์ตี้อื่นๆ

การสร้างออบเจ็กต์ฟีเจอร์

หากต้องการสร้าง 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 หลัก 1 รายการที่จัดเก็บไว้ในพร็อพเพอร์ตี้ geometry ระบบอาจจัดเก็บเรขาคณิตเพิ่มเติมในพร็อพเพอร์ตี้อื่นๆ Geometry ยังมีเมธอดต่างๆ เช่น การซ้อนทับและบัฟเฟอร์ใน Feature เพื่อความสะดวกในการรับ Geometry หลัก การใช้การดำเนินการ และการตั้งค่าผลลัพธ์เป็น Geometry หลักใหม่ ผลลัพธ์จะเก็บรักษาพร็อพเพอร์ตี้อื่นๆ ทั้งหมดของ 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() จะเขียนทับพร็อพเพอร์ตี้ที่มีอยู่