FeatureCollection 概览

一组相关地图项可以合并到一个 FeatureCollection 中,以便对整个集合执行其他操作,例如过滤、排序和渲染。 除了简单地图项(几何图形 + 属性)之外,地图项集合还可以包含其他集合。

FeatureCollection 构造函数

创建 FeatureCollection 的一种方法是向构造函数提供一系列功能。这些地图项不必具有相同的几何图形类型或相同的属性。例如:

Code Editor (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)

单个几何图形也可以转换为仅包含一个 FeatureFeatureCollection

Code Editor (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 构造函数提供表 ID。例如,如需加载 RESOLVE 生态区域数据,请执行以下操作:

Code Editor (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 中搜索表格数据集。

随机抽样

如需获取指定区域中的一组随机点,您可以使用以下方法:

Code Editor (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)