ee.FeatureCollection.randomPoints Stay organized with collections Save and categorize content based on your preferences.
Page Summary
ee.FeatureCollection.randomPointsgenerates points that are uniformly random within a given geometry.The distribution of the generated points depends on the dimension of the input geometry.
The function takes arguments for the region, number of points, seed for randomness, and maximum error.
The function returns a FeatureCollection of the generated points.
Examples are provided for generating random points using both JavaScript and Python.
| Usage | Returns |
|---|---|
ee.FeatureCollection.randomPoints(region,points,seed,maxError) | FeatureCollection |
| Argument | Type | Details |
|---|---|---|
region | Geometry | The region to generate points for. |
points | Integer, default: 1000 | The number of points to generate. |
seed | Long, default: 0 | A seed for the random number generator. |
maxError | ErrorMargin, optional | The maximum amount of error tolerated when performing any necessary reprojection. |
Examples
Code Editor (JavaScript)
// An ee.Geometry to constrain the geographic bounds of random points.varregion=ee.Geometry.Rectangle({coords:[-113.5,40.0,-110.2,41.9],geodesic:false});// Generate 50 random points with the region.varrandomPoints=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 setup
See the Python Environment page for information on the Python API and usinggeemap for interactive development.
importeeimportgeemap.coreasgeemap
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
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-02-20 UTC.