公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.FeatureCollection.randomPoints
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在给定几何图形中生成均匀随机的点。如果几何图形是二维(多边形或多边形),则返回的点会均匀分布在球体的给定区域上。如果几何图形是一维的(线串),则返回的点会沿着几何图形的边缘均匀插值。如果几何图形的维度为零(点),则系统会从输入点均匀抽取返回的点。如果给定的是混合维度的多几何图形,则系统会从维度最高的组成几何图形中采样点。
用法 | 返回 |
---|
ee.FeatureCollection.randomPoints(region, points, seed, maxError) | FeatureCollection |
参数 | 类型 | 详细信息 |
---|
region | 几何图形 | 要为其生成点的区域。 |
points | 整数,默认值:1000 | 要生成的点数。 |
seed | 长整数,默认值:0 | 随机数生成器的种子。 |
maxError | ErrorMargin,可选 | 执行任何必要的重新投影时允许的最大误差量。 |
示例
Code Editor (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 API 以及如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):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"],null,[]]