公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.FeatureCollection.distance
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
生成一个 DOUBLE 图像,其中每个像素都是从像素中心到集合中最近的 Point、LineString 或多边形边界的距离(以米为单位)。请注意,距离也是在多边形的内部测量的。不在几何图形“searchRadius”米范围内的像素将被遮盖。
距离是在球面上计算的,因此存在一个与每个像素和最近几何图形之间的纬度差成正比的小误差。
用法 | 返回 |
---|
FeatureCollection.distance(searchRadius, maxError) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:features | FeatureCollection | 用于获取特征的要素集合,这些特征用于计算像素距离。 |
searchRadius | 浮点数,默认值:100000 | 查找边缘时,每个像素的最大距离(以米为单位)。除非在此距离内有边缘,否则像素将被遮盖。 |
maxError | 浮点数,默认值:100 | 以米为单位的最大重投影误差,仅当输入折线需要重投影时使用。如果提供“0”,则在需要投影时,此操作将失败。 |
示例
代码编辑器 (JavaScript)
// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
.filter('country_lg == "Belgium"');
// Generate an image of distance to nearest power plant.
var distance = fc.distance({searchRadius: 50000, maxError: 50});
// Display the image and FeatureCollection on the map.
Map.setCenter(4.56, 50.78, 7);
Map.addLayer(distance, {max: 50000}, 'Distance to power plants');
Map.addLayer(fc, {color: 'red'}, 'Power plants');
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
'country_lg == "Belgium"'
)
# Generate an image of distance to nearest power plant.
distance = fc.distance(searchRadius=50000, maxError=50)
# Display the image and FeatureCollection on the map.
m = geemap.Map()
m.set_center(4.56, 50.78, 7)
m.add_layer(distance, {'max': 50000}, 'Distance to power plants')
m.add_layer(fc, {'color': 'red'}, 'Power plants')
m
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,[]]