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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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