I want to write a function that takes class id and number of points for each class as argument and samples points from polygons, returning a FeatureCollection
.
I could only write a function that samples the same number of points [100 points in the example] for each class with iteration as below:
GEE Link: Reproducible GEE Example
Let me know if you can't open the polygon file
// Reproducible Example for Training Point Sampling
// Create id List
var idList = ee.List.sequence(11, 13).map(function(x) {return ee.Number(x)});
// Extraction Function
var collectTrain = function(id, featureCol) {
// cast
id = ee.Number(id);
featureCol = ee.FeatureCollection(featureCol);
// Extract
var point = ee.FeatureCollection.randomPoints(
polygons.filter(ee.Filter.eq('id', id)), 100)
.map(function(feat){
feat = ee.Feature(feat);
return feat.set('id', id);
});
return featureCol.merge(point);
};
// Initial FeatureCollection
var point = ee.FeatureCollection.randomPoints(
polygons.filter(ee.Filter.eq('id', 11)), 1)
.map(function(feat){
feat = ee.Feature(feat);
return feat.set('id', 11);
});
//Iterate over idList starting from the initial point
var training = ee.FeatureCollection(idList.iterate(collectTrain, point));
print(training);
How could we write such a function that takes two lists as arguments, such as in R
with purrr::map2
and works with iterating those two lists. Arguments should be like:
id = [11, 12, 13]
point = [100, 150, 120]