ee.FeatureCollection.randomPoints
Generates points that are uniformly random in the given geometry. If the geometry is two-dimensional (polygon or multi-polygon) then the returned points are uniformly distributed on the given region of the sphere. If the geometry is one-dimensional (linestrings), the returned points are interpolated uniformly along the geometry's edges. If the geometry has dimension zero (points), the returned points are sampled uniformly from the input points. If a multi-geometry of mixed dimension is given, points are sampled from the component geometries with the highest dimension.
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
// 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 setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
# 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 the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-02-20 UTC.
[null,null,["Last updated 2024-02-20 UTC."],[[["`ee.FeatureCollection.randomPoints` generates uniformly random points within a specified geometry, such as polygons, linestrings, or points."],["The distribution of points varies based on the geometry's dimension: uniform on the surface for polygons, along edges for linestrings, and from input points for point geometries."],["The function takes parameters like `region` (geometry), `points` (number of points), `seed` (for reproducibility), and `maxError` (for reprojection tolerance)."],["Users can specify the desired number of random points to generate and provide a seed value for consistent results."],["If a mixed-dimension geometry is provided, the function samples points from the highest-dimension component."]]],["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"]]