[GIS] Create random points using Earth Engine

google-earth-engine

I'm applying a function that distributes 500 points within the FeatureCollection.`

var getSamples = function(image, samplesFcs, samplesPoints, nsamples, label){

  var samplesCollection = ee.List(samplesFcs).iterate(
    function(sample,totalSample){
        return ee.FeatureCollection(totalSample).merge(sample);
      }
    ,ee.FeatureCollection([]));

    samplesCollection = ee.FeatureCollection(samplesCollection)
    return samplesCollection

    var randomPoints = ee.FeatureCollection.randomPoints(samplesCollection, nsamples, 1989)

      samplesPoints.forEach(function(points) {
        randomPoints = randomPoints.merge(points);
      })

     return randomPoints
}

however it is wrong, after all, when I give a print on the console to check how many points were sampled inside the Features, the number returned is about Features within the FeatureCollection, as opposed to the number of samples

var test = getSamples(addndvi_2018,class4,class4Points,nsamples)
print(teste.size(),'samples Vegetation')

Can anyone point to where I'm doing wrong here?

Best Answer

At line 36 you have nSamples instead of nsamples.

Related Question