Thank you @PierrickRambaud!
With .map
it was no problem in the end:
// Sample 50 random points from this tile geometry
var randomPoints = ee.FeatureCollection.randomPoints({
region: geometry,
points: 50, // Number of random points per tile
seed: 42, // Seed for reproducibility
maxError: 1 // Tolerance for random point generation
});
// Sample image at the random points
var sampledData = myImage.sampleRegions({
collection: randomPoints,
scale: 10000, // Sampling scale (depends on the pixel size)
geometries: true
});
// Return the sample with the tile ID
return sampledData.map(function(feature) {
return feature.set('tile_id', tileId); // Add tile ID to each sampled point
});
};
// Apply the sampling to each tile in the grid and combine the results
var sampledPoints = gridFc.map(sampleFromTile).flatten();
This creates a combined feature collection with all the combined samples.