1

I want to transform a ee.Iamge that descripbe the ecozone of a specific country to a vector. I try to reproduce this example but I cannot get anything else than black vector...


//load the country 
var country = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(ee.Filter.eq('country_co', 'CG'));

//load the ecozones
var gez_2010 = ee.Image('users/bornToBeAlive/gez_2010_wgs84')
var country_gez_2010 =  gez_2010.select('b1').clip(country)

country_gez_2010 has only one band b1 with int values from 0 to 21.

//construct the zones  
var zones = country_gez_2010.eq(0)
var i
for (i=1; i<21;i++){
    zones = zones.add(country_gez_2010.eq(i))
}

//Convert the ecozones to vectors.
var vectors = zones.addBands(country_gez_2010).reduceToVectors({
    'geometry': country,
    'crs': country_gez_2010.projection(),
    'scale': 100,
    'geometryType': 'polygon',
    'eightConnected': false,
    'labelProperty': 'ecozone',
    'reducer': ee.Reducer.min(),
    'maxPixels': 1e9
})

//display it on the map
var display = ee.Image(0).updateMask(0).paint(vectors, '000000');
Map.addLayer(display, {palette: '000000'}, 'vectors');

I'm doubting on the zones definition and the reducer selection but maybe it's something else

2
  • Please share a complete example which produces the black vector. As of now, we cannot run your code (error: "country" is not defined in this scope), so we can't help you debug it. When you share the code, please also share the corresponding assets used in the code.
    – kkrao
    Jul 13, 2020 at 4:45
  • sorry, I did forget that on GEE with the name of the asset you can actually run the code. I added a simple definition of the AOI Jul 13, 2020 at 4:52

1 Answer 1

0

I change the reducer to a more appropriate one

// Run reduceToVectors per class by masking all other classes.
var classes = country_gez_2010.reduceToVectors({
  reducer: ee.Reducer.countEvery(), 
  geometry: country, 
  scale: 100,
  maxPixels: 1e10
});
var result = ee.FeatureCollection(classes);
Map.addLayer(result);

it leads to the exact definition of my ecozones

1
  • That's great. Glad you found the solution yourself.
    – kkrao
    Jul 13, 2020 at 16:21

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.