公告:凡是在 
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取。如未在 2025 年 9 月 26 日前完成驗證,存取權可能會暫停。
  
        
 
       
     
  
  
  
    
  
  
  
    
      ee.FeatureCollection.randomPoints
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
  
  
會在指定幾何圖形中產生均勻隨機的點。如果幾何圖形是二維 (多邊形或多邊形),則系統會將傳回的點均勻分布在球體的特定區域。如果幾何圖形是一維 (LineString),則系統會沿著幾何圖形的邊緣,均勻插補傳回的點。如果幾何圖形的維度為零 (點),則系統會從輸入點均勻取樣傳回的點。如果提供混合維度的多重幾何圖形,系統會從維度最高的元件幾何圖形中取樣點。
| 用量 | 傳回 | 
|---|
| ee.FeatureCollection.randomPoints(region, points, seed, maxError) | FeatureCollection | 
| 引數 | 類型 | 詳細資料 | 
|---|
| region | 幾何圖形 | 要產生點的區域。 | 
| points | 整數,預設值:1000 | 要產生的點數數量。 | 
| seed | Long,預設值:0 | 隨機號碼產生器的種子。 | 
| maxError | ErrorMargin (選用) | 執行任何必要的重新投影作業時,可容許的最大誤差值。 | 
  
  
  範例
  
    
  
  
    
    
  
  
  
  
    
    
    
      程式碼編輯器 (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
  
  
  
  
  
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
  上次更新時間:2025-07-25 (世界標準時間)。
  
  
  
    
      [null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[],["The `ee.FeatureCollection.randomPoints` function generates a specified number of random points within a given geometry.  The points are uniformly distributed within the geometry's area if it's two-dimensional, along its edges if one-dimensional, or sampled from the input points if zero-dimensional. For mixed-dimension multi-geometries, points are drawn from the highest-dimension components. The user defines the `region`, the number of `points`, a random `seed`, and an optional `maxError`.\n"]]