ee.FeatureCollection.distance

生成一个 DOUBLE 图像,其中每个像素都是从像素中心到集合中最近的 Point、LineString 或多边形边界的距离(以米为单位)。请注意,距离也是在多边形的内部测量的。不在几何图形“searchRadius”米范围内的像素将被遮盖。

距离是在球面上计算的,因此存在一个与每个像素和最近几何图形之间的纬度差成正比的小误差。

用法返回
FeatureCollection.distance(searchRadius, maxError)图片
参数类型详细信息
此:featuresFeatureCollection用于获取特征的要素集合,这些特征用于计算像素距离。
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