ee.Feature.buffer

傳回緩衝指定距離的輸入內容。如果距離為正值,幾何圖形會擴大;如果距離為負值,幾何圖形會縮小。

用量傳回
Feature.buffer(distance, maxError, proj)功能
引數類型詳細資料
這個:feature元素要緩衝幾何圖形的功能。
distance浮點值緩衝區的距離,可能為負值。如未指定投影,則單位為公尺。否則單位會採用投影的座標系統。
maxErrorErrorMargin,預設值:null近似緩衝圓圈和執行任何必要重新投影時,可容許的最大誤差量。如未指定,則預設為距離的 1%。
proj投影,預設值:null如果指定,緩衝區會在這個投影中執行,距離會解讀為這個投影的座標系統單位。否則,系統會將距離解讀為公尺,並在球體座標系統中執行緩衝處理。

範例

程式碼編輯器 (JavaScript)

// Polygon feature of Serengeti National Park.
var feature = ee.FeatureCollection('WCMC/WDPA/202307/polygons')
                  .filter('ORIG_NAME == "Serengeti National Park"')
                  .first();

// Cast the resulting object as an ee.Feature so that the call to the buffer
// method is unambiguous (first() and buffer() are shared by multiple classes).
feature = ee.Feature(feature);

// Generate buffered features out and in from the original boundary.
var bufferOut = feature.buffer(10000);  // 10 km out
var bufferIn = feature.buffer(-10000);  // 10 km in

// Display the features on the map.
Map.addLayer(bufferOut, {color: 'red'}, 'Buffer out');
Map.addLayer(feature, {color: 'blue'}, 'No buffer');
Map.addLayer(bufferIn, {color: 'yellow'}, 'Buffer in');
Map.setCenter(34.8407, -2.398, 8);

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# Polygon feature of Serengeti National Park.
feature = (
    ee.FeatureCollection('WCMC/WDPA/202307/polygons')
    .filter('ORIG_NAME == "Serengeti National Park"')
    .first()
)

# Cast the resulting object as an ee.Feature so that the call to the buffer
# method is unambiguous (first() and buffer() are shared by multiple classes).
feature = ee.Feature(feature)

# Generate buffered features out and in from the original boundary.
buffer_out = feature.buffer(10000)  # 10 km out
buffer_in = feature.buffer(-10000)  # 10 km in

# Display the features on the map.
m = geemap.Map()
m.add_layer(buffer_out, {'color': 'red'}, 'Buffer out')
m.add_layer(feature, {'color': 'blue'}, 'No buffer')
m.add_layer(buffer_in, {'color': 'yellow'}, 'Buffer in')
m.set_center(34.8407, -2.398, 8)
m