1

I created a grid (featurecollection containing various rectangular features) by coveringGrid function, and now I want to sample 10 points within a feature, and for every feature in this featurecollection.

var grid = geometry1.coveringGrid('EPSG:4326', 500000); 
// 'geometry1': a polygon that I draw

This code for the first feature works :

var list = ee.FeatureCollection.randomPoints({
    region:grid.geometry().geometries().get(0), points:10});

However, this code for all features does not work (It gave me an empty list of the same length of the featurecollection):

var list = ee.List.sequence({start:0, end:959, step:1});
list = list.map(function(n){
  return ee.FeatureCollection.randomPoints({
    region:grid.geometry().geometries().get(n), points:10})
});
print(list);

// end:959 is the length of the featurecollection.

Does anyone know how to solve the problem?

1 Answer 1

0

Your list is indexed from 0 so the end should be 958.

This works for me:

var grid = geometry.coveringGrid('EPSG:4326', 100000); 
print(grid.size())
var list = ee.FeatureCollection.randomPoints({
    region:grid.geometry().geometries().get(0), points:10});
print(list);
Map.addLayer(list, {}, 'list')
    
var list = ee.List.sequence({start:0, end:grid.size().subtract(1), step:1});
list = ee.FeatureCollection(list.map(function(n){
  return ee.FeatureCollection.randomPoints({
    region:grid.geometry().geometries().get(n), points:10})
}));
print(list.flatten().size());
Map.addLayer(list.flatten(), {}, 'list')

Your Answer

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

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