TransWikia.com

Reclassifying and vectorizing specifc classes in Google Earth Engine

Geographic Information Systems Asked on May 29, 2021

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?

One Answer

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]);

Correct answer by Paris on May 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP