ee.FeatureCollection
时间: 2025-07-06 12:48:13 浏览: 10
### Earth Engine `FeatureCollection` 使用与方法
#### 创建 `FeatureCollection`
可以通过多种方式创建 `ee.FeatureCollection` 对象。最常见的方式是从几何对象、特征或现有集合构建。
```javascript
// 定义一个点并创建单个要素
var point = ee.Geometry.Point([-122.082, 37.42]);
var feature = ee.Feature(point, {name: 'Location'});
// 将多个要素组合成 FeatureCollection
var collection = ee.FeatureCollection([feature]);
print(collection);
```
也可以通过加载预定义的数据集来获取 `FeatureCollection`:
```python
import ee
# 初始化Earth Engine API
ee.Initialize()
# 加载全球行政边界数据作为 FeatureCollection
dataset = ee.FeatureCollection('TIGER/2018/States')
print(dataset.getInfo())
```
#### 添加新要素到已有集合
可以向现有的 `FeatureCollection` 中添加新的要素,这通常用于逐步构建复杂的空间分析单元。
```javascript
// 新增一个点并与原有集合合并
var newPoint = ee.Geometry.Point([-122.09, 37.42]);
var newFeature = ee.Feature(newPoint, {'name': 'New Location'});
collection = collection.merge(ee.FeatureCollection([newFeature]));
print(collection.size()); // 输出数量确认增加成功
```
#### 过滤和查询 `FeatureCollection`
利用过滤器可以根据属性值筛选特定条件下的要素子集。
```python
# 基于属性过滤 StateName 属性等于 California 的州级区域
california = dataset.filterMetadata('STATEFP', 'equals', '06')
# 获取结果中的第一个要素查看其详情
first_feature = california.first()
properties = first_feature.toDictionary().getInfo()
for key in properties.keys():
print(f"{key}: {properties[key]}")
```
#### 应用空间操作
支持执行各种地理处理任务,比如缓冲区分析、交集计算等。
```javascript
// 计算每个要素周围半径为5公里的缓冲区
buffered = collection.map(function(feature){
return feature.buffer(5000); // 单位米
});
Map.addLayer(buffered, {}, "Buffered Points");
```
阅读全文
相关推荐















