1

I need to sample NDVI time series on the crop classe defined in the Copernicus GLDAS Landover dataset (value: 40). The logical approach seems to be using Image.stratifiedSample on the landcover, retrieve a featureCollection and use it to sample NDVI from another dataset. However I get a EEException: An internal error has occurred upon defining the stratified sample with the code below. Can anyone spot what is wrong? Or is there a better approach I haven't seen?

import ee
ee.Initialize()

xmin = -72
xmax = -67
ymin = -42
ymax = -39

ROI = ee.Geometry.Rectangle([xmin, ymin, xmax, ymax])

coper = ee.ImageCollection("COPERNICUS/Landcover/100m/Proba-V-C3/Global").first().select('discrete_classification')
coper = coper.clip(ROI)

points = coper.stratifiedSample(
  numPoints=10, 
  classBand='discrete_classification', 
  region=ROI, 
  scale=100,
  classValues=[40]
)

task = ee.batch.Export.table.toDrive(collection=points, fileFormat='GeoJSON')
task.start()

1 Answer 1

1

According to the GEE documnetation, it appears that classValues argumnent requires classPoints to also be specified. These arguments provide information on the class values for which to override the numPixels paramter. To sample exclusively from a single class, I suggest masking your image before calling Image.stratifiedSample:

points = coper.updateMask(coper.eq(40)).stratifiedSample(
  numPoints=10, 
  classBand='discrete_classification', 
  region=ROI, 
  scale=100
)
0

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.