ee.FeatureCollection.randomPoints

會在指定幾何圖形中產生均勻隨機的點。如果幾何圖形是二維 (多邊形或多邊形),則系統會將傳回的點均勻分布在球體的特定區域。如果幾何圖形是一維 (LineString),則系統會沿著幾何圖形的邊緣,均勻插補傳回的點。如果幾何圖形的維度為零 (點),則系統會從輸入點均勻取樣傳回的點。如果提供混合維度的多重幾何圖形,系統會從維度最高的元件幾何圖形中取樣點。

用量傳回
ee.FeatureCollection.randomPoints(region, points, seed, maxError)FeatureCollection
引數類型詳細資料
region幾何圖形要產生點的區域。
points整數,預設值:1000要產生的點數數量。
seedLong,預設值:0隨機號碼產生器的種子。
maxErrorErrorMargin (選用)執行任何必要的重新投影作業時,可容許的最大誤差值。

範例

程式碼編輯器 (JavaScript)

// An ee.Geometry to constrain the geographic bounds of random points.
var region = ee.Geometry.Rectangle(
    {coords: [-113.5, 40.0, -110.2, 41.9], geodesic: false});

// Generate 50 random points with the region.
var randomPoints = ee.FeatureCollection.randomPoints(
    {region: region, points: 50, seed: 0, maxError: 1});

print('Random points from within the defined region', randomPoints);
Map.setCenter(-111.802, 40.979, 7);
Map.addLayer(region, {color: 'yellow'}, 'Region');
Map.addLayer(randomPoints, {color: 'black'}, 'Random points');

Python 設定

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

import ee
import geemap.core as geemap

Colab (Python)

# An ee.Geometry to constrain the geographic bounds of random points.
region = ee.Geometry.Rectangle(
    coords=[-113.5, 40.0, -110.2, 41.9], proj='EPSG:4326', geodesic=False
)

# Generate 50 random points with the region.
random_points = ee.FeatureCollection.randomPoints(
    region=region, points=50, seed=0, maxError=1
)

display('Random points from within the defined region', random_points)
m = geemap.Map()
m.set_center(-111.802, 40.979, 7)
m.add_layer(region, {'color': 'yellow'}, 'Region')
m.add_layer(random_points, {'color': 'black'}, 'Random points')
m