Tổng quan về FeatureCollection

Bạn có thể kết hợp các nhóm tính năng có liên quan thành một FeatureCollection để cho phép thực hiện các thao tác bổ sung trên toàn bộ tập hợp, chẳng hạn như lọc, sắp xếp và kết xuất. Ngoài các đối tượng đơn giản (hình học + thuộc tính), tập hợp các đối tượng cũng có thể chứa các tập hợp khác.

Hàm khởi tạo FeatureCollection

Một cách để tạo FeatureCollection là cung cấp cho hàm khởi tạo một danh sách các tính năng. Các đặc điểm không cần phải có cùng loại hình học hoặc cùng thuộc tính. Ví dụ:

Trình soạn thảo mã (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);

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

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)

Bạn cũng có thể biến các hình học riêng lẻ thành một FeatureCollection chỉ có một Feature:

Trình soạn thảo mã (JavaScript)

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

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

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)

Tập dữ liệu dạng bảng

Earth Engine lưu trữ nhiều tập dữ liệu dạng bảng. Để tải tập dữ liệu bảng, hãy cung cấp mã nhận dạng bảng cho hàm khởi tạo FeatureCollection. Ví dụ: để tải dữ liệu về Khu sinh thái RESOLVE:

Trình soạn thảo mã (JavaScript)

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

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

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)

Lưu ý rằng giống như với tập dữ liệu hình ảnh, bạn có thể tìm kiếm tập dữ liệu bảng trong Danh mục dữ liệu Earth Engine.

Mẫu ngẫu nhiên

Để lấy một tập hợp các điểm ngẫu nhiên trong một khu vực cụ thể, bạn có thể sử dụng:

Trình soạn thảo mã (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');

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

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)