公告:凡是在
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 環境頁面,瞭解 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
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eComputes the distance (in meters) from each pixel to the nearest point, line, or polygon within a given FeatureCollection.\u003c/p\u003e\n"],["\u003cp\u003eGenerates a double-precision image where pixel values represent the distance to the nearest feature.\u003c/p\u003e\n"],["\u003cp\u003eOffers adjustable search radius and maximum error parameters for controlling computation.\u003c/p\u003e\n"],["\u003cp\u003ePixels beyond the search radius or exceeding the error threshold are masked out.\u003c/p\u003e\n"],["\u003cp\u003eCalculations consider the Earth's curvature for accurate distance measurements.\u003c/p\u003e\n"]]],[],null,["# ee.FeatureCollection.distance\n\nProduces a DOUBLE image where each pixel is the distance in meters from the pixel center to the nearest Point, LineString, or polygonal boundary in the collection. Note distance is also measured within interiors of polygons. Pixels that are not within 'searchRadius' meters of a geometry will be masked out.\n\n\u003cbr /\u003e\n\nDistances are computed on a sphere, so there is a small error proportional to the latitude difference between each pixel and the nearest geometry.\n\n| Usage | Returns |\n|---------------------------------------------------------------|---------|\n| FeatureCollection.distance`(`*searchRadius* `, `*maxError*`)` | Image |\n\n| Argument | Type | Details |\n|------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `features` | FeatureCollection | Feature collection from which to get features used to compute pixel distances. |\n| `searchRadius` | Float, default: 100000 | Maximum distance in meters from each pixel to look for edges. Pixels will be masked unless there are edges within this distance. |\n| `maxError` | Float, default: 100 | Maximum reprojection error in meters, only used if the input polylines require reprojection. If '0' is provided, then this operation will fail if projection is required. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// FeatureCollection of power plants in Belgium.\nvar fc = ee.FeatureCollection('WRI/GPPD/power_plants')\n .filter('country_lg == \"Belgium\"');\n\n// Generate an image of distance to nearest power plant.\nvar distance = fc.distance({searchRadius: 50000, maxError: 50});\n\n// Display the image and FeatureCollection on the map.\nMap.setCenter(4.56, 50.78, 7);\nMap.addLayer(distance, {max: 50000}, 'Distance to power plants');\nMap.addLayer(fc, {color: 'red'}, 'Power plants');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# FeatureCollection of power plants in Belgium.\nfc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(\n 'country_lg == \"Belgium\"'\n)\n\n# Generate an image of distance to nearest power plant.\ndistance = fc.distance(searchRadius=50000, maxError=50)\n\n# Display the image and FeatureCollection on the map.\nm = geemap.Map()\nm.set_center(4.56, 50.78, 7)\nm.add_layer(distance, {'max': 50000}, 'Distance to power plants')\nm.add_layer(fc, {'color': 'red'}, 'Power plants')\nm\n```"]]