1

I want to have random points across Peru and their properties (the band values of IMAGE) for statistical analysis in GEE. I found two options which are sampling and random points. I have tried the following lines:

var samplevalues= IMAGE.sample({ region: peru.geometry(),numPixels: 10000, geometries: true});
var randompoints = ee.FeatureCollection.randomPoints(peru.geometry(), 1000).set('samplenumber');

None of them gave me the desired output. samplevalues keeps the bands in IMAGE and shows them as properties of each sample points, but the points are within IMAGE borders. Whereas, randompoints gives points without properties across Peru.

How can I get random points over Peru, and IMAGE bands as their properties?

1 Answer 1

3

Use sampleRegions to add the image bands as properties to the collection of random points.

var randompoints = ee.FeatureCollection.randomPoints(peru.geometry(), 1000);
var samples = IMAGE.sampleRegions({
  collection: randompoints,
  geometries: true,
});
print(samples);

sampleRegions is very similar to sample, but it chooses points from within the given regions (so if the regions are themselves points, you get those points as results).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.