-1

My raster file has 29 classes and I applied 'Reclassify by table' in QGIS 3.16 to assign 1 to classes 15 and 24 only and all other classes were classified as 0. I applied the following script to polygonize these two classes which works fine without the reclassify part.

 var image = ee.Image("users/parivash89/verceli_tiles_3")
      .toInt();
 var oldgroup = ee.List([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]);
 var newgroup = ee.List([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0]);

    Map.addLayer(newgroup );
    Map.centerObject(newgroup );
    
    var classes = newgroup .reduceToVectors({
      reducer: ee.Reducer.countEvery(), 
      scale: 10,
      maxPixels: 1e10
    });
    
    var result = ee.FeatureCollection(classes);
    
    Map.addLayer(result);
    
    // Export the FeatureCollection to a SHP file.
    Export.table.toDrive({
      collection: result,
      folder: 'GEE_Polygonize',
      description:'Vercelli_tiles_3',
      fileFormat: 'SHP'
    });

But when I add the reclasify part, I get this error:

Cannot add an object of type <List> to the map.
    in <global>, line 67
    in <global>, line 83

What should I add to choose the selected classes only and polygonize only them?

4
  • 1
    Please provide complete example which reproduces the error you mention. As of now, newgroup is not defined.
    – kkrao
    Commented Apr 8, 2021 at 7:22
  • Thanks @kkrao, I thought I defined it by indicating the var newgroup. Maybe that is my error. I changed the code as I run it in the question
    – Paris
    Commented Apr 8, 2021 at 14:10
  • 1
    I am still unable to reproduce your error. Please share the image asset (make it public). The current error is: Image (Error) Image.load: Image asset 'users/parivash89/verceli_tiles_3' not found.
    – kkrao
    Commented Apr 9, 2021 at 16:06
  • Thanks @kkrao. I realized what was my mistake. I add my answer. Thanks for your help.
    – Paris
    Commented Apr 12, 2021 at 8:14

1 Answer 1

0

Remap function was my answer since I was tring to operate on individual values. By adding these lines, the script was done:

.remap([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29],
       [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,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.