ภาพรวมของ FeatureCollection

คุณรวมกลุ่มฟีเจอร์ที่เกี่ยวข้องเข้าเป็น FeatureCollection ได้เพื่อเปิดใช้การดำเนินการเพิ่มเติมกับทั้งชุด เช่น การกรอง การจัดเรียง และการแสดงผล นอกจากองค์ประกอบพื้นฐาน (เรขาคณิต + พร็อพเพอร์ตี้) แล้ว คอลเล็กชันองค์ประกอบยังมีคอลเล็กชันอื่นๆ ได้ด้วย

ตัวสร้าง FeatureCollection

วิธีหนึ่งในการสร้าง FeatureCollection คือระบุรายการฟีเจอร์ให้กับคอนสตรคเตอร์ ฟีเจอร์ไม่จำเป็นต้องมีประเภทเรขาคณิตหรือพร็อพเพอร์ตี้เดียวกัน เช่น

เครื่องมือแก้ไขโค้ด (JavaScript)

// Make a list of Features.
var features = [
  ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
];

// Create a FeatureCollection from the list and print it.
var fromList = ee.FeatureCollection(features);
print(fromList);

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

# Make a list of Features.
features = [
    ee.Feature(
        ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {'name': 'Voronoi'}
    ),
    ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}),
    ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'}),
]

# Create a FeatureCollection from the list and print it.
from_list = ee.FeatureCollection(features)
display(from_list)

นอกจากนี้ คุณยังเปลี่ยนเรขาคณิตแต่ละรายการให้เป็น FeatureCollection ของ Feature รายการเดียวได้ด้วย โดยทำดังนี้

เครื่องมือแก้ไขโค้ด (JavaScript)

// Create a FeatureCollection from a single geometry and print it.
var fromGeom = ee.FeatureCollection(ee.Geometry.Point(16.37, 48.225));
print(fromGeom);

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

# Create a FeatureCollection from a single geometry and print it.
from_geom = ee.FeatureCollection(ee.Geometry.Point(16.37, 48.225))
display(from_geom)

ชุดข้อมูลตาราง

Earth Engine โฮสต์ชุดข้อมูลตารางที่หลากหลาย หากต้องการโหลดชุดข้อมูลตาราง ให้ระบุรหัสตารางให้กับคอนสตรคเตอร์ FeatureCollection เช่น หากต้องการโหลดข้อมูลเขตนิเวศ RESOLVE ให้ทำดังนี้

เครื่องมือแก้ไขโค้ด (JavaScript)

var fc = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017');
Map.setCenter(12.17, 20.96, 3);
Map.addLayer(fc, {}, 'ecoregions');

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

fc = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017')
m = geemap.Map()
m.set_center(12.17, 20.96, 3)
m.add_layer(fc, {}, 'ecoregions')
display(m)

โปรดทราบว่าคุณสามารถค้นหาชุดข้อมูลตารางใน Earth Engine Data Catalog ได้เช่นเดียวกับชุดข้อมูลรูปภาพ

ตัวอย่างแบบสุ่ม

หากต้องการรับคอลเล็กชันจุดแบบสุ่มในภูมิภาคที่ระบุ ให้ใช้สิ่งต่อไปนี้

เครื่องมือแก้ไขโค้ด (JavaScript)

// Define an arbitrary region in which to compute random points.
var region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064);

// Create 1000 random points in the region.
var randomPoints = ee.FeatureCollection.randomPoints(region);

// Display the points.
Map.centerObject(randomPoints);
Map.addLayer(randomPoints, {}, 'random points');

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

# Define an arbitrary region in which to compute random points.
region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064)

# Create 1000 random points in the region.
random_points = ee.FeatureCollection.randomPoints(region)

# Display the points.
m = geemap.Map()
m.center_object(random_points)
m.add_layer(random_points, {}, 'random points')
display(m)