I'm looking to convert values between 4.45 and 10 in index FI into a vector polygon. I will be then be using this vector to clip my images prior to clustering. So the result must be clusters of L8 collection within the AOI defined by those said values in FI index. However, that is not the result produced. The vector conversion works but it includes two zones - i) between 4.45 and 10 and ii) outside these values.

Could someone help please? Code below.

var clusters = L8sr_ndvi_lswi_bsi_fi.map(function(image){
  var imgClip = image.clip(AOI)
  var imgFi = imgClip.select("fi");//
  //var zones = imgFi.updateMask(imgFi.lte(10)).updateMask(imgFi.gt(4.45))//
  var zones = imgFi.lte(10).add(imgFi.gt(4.45));
  zones = zones.updateMask(zones.neq(0));

  // Convert the zones to vectors.
  var vectors = zones.reduceToVectors({
    geometry: AOI,
    crs: imgFi.projection(),
    scale: 10,
    geometryType: 'polygon',
    eightConnected: false,
  var updImg = imgClip.clip(vectors)//
  var training = updImg.select("B1" , "B2", "B3",  "B4" , "B5", "B6", "B7","lswi","ndvi","bsi")
  region: vectors,
  scale: 30,
  numPixels: 100
  // Instantiate the clusterer and train it
  // specify the number of Clusters
  var clusterer = ee.Clusterer.wekaKMeans(10).train(training)
  return imgClip.cluster(clusterer);//result = 

1 Answer 1


Don't use add to combine the two logical relations, use and():

var zones = imgFi.lte(10).and(imgFi.gt(4.45));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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