1

with this code I created a land use time series:

var imgCol = ee.ImageCollection('users/danielepiccolo/consumo_suolo/CS_ARPAV')
  .select('b1');

var region = ee.FeatureCollection('users/danielepiccolo/Shapefile/Veneto');

var histCol = ee.FeatureCollection(imgCol.map(function(img) {
  var hist = img.reduceRegion({
    reducer: ee.Reducer.frequencyHistogram(),
    geometry: region,
    scale: 10,
    maxPixels: 1e13
  });
  return ee.Feature(null, hist.get('b1')).copyProperties(img, ['anno']);
})).filter(ee.Filter.notNull(['anno']));


var xProps = histCol.first()
  .propertyNames().filter(ee.Filter.neq('item', 'anno'));

var chart = ui.Chart.feature.byProperty({
  features: histCol,
  xProperties: xProps,
  seriesProperty: 'anno'
}).setOptions({
  title: 'Class histogram per year',
  hAxis: {
    title: 'Class',
  },
  vAxis: {
    title: 'Frequency',
  }
});
print(chart);

Now I would like to assign the corresponding labels to the values ​​and sort them following this list:

"1 - Suolo consumato", "2 - Suolo non consumato", "11 - Suolo consumato permanente", "12 - Suolo consumato reversibile", "111 - Edifici, fabbricati, capannoni", "112 - Strade asfaltate", "113 - Sede ferroviaria", "114 - Aeroporti", "115 - Porti", "116 - Altre aree impermeabili/pavimentate non edificate", "117 - Serre permanenti pavimentate", "118 - Discariche", "121 - Strade sterrate", "122 - Cantieri e altre aree in terra battuta", "123 - Aree estrattive non rinaturalizzate", "124 - Cave in falda", "125 - Campi fotovoltaici a terra", "126 - Altre coperture artificiali la cui rimozione ripristina le condizioni iniziali del suolo", "201 - Corpi idrici artificiali", "202 - Rotonde e svincoli (aree permeabili)", "203 - Serre non pavimentate", "204 - Ponti e viadotti su suolo non artificiale"

I thought of putting a .setSeriesNames with the list of labels in the chart code but unsuccessful. I tried to replace values but unsuccessful.

Do you have any suggestions?

1 Answer 1

0

You could do this by creating a dictionary from your list and then assign them to your features. Something like:

var labels = {
  '1': 'Suolo consumato',
  '2': 'Suolo non consumato',
  ///// ... etc...
};

//// Then use the above dictionary to update the features properties
histCol = histCol.map(function(feature) {
  var properties = feature.toDictionary();
  var newProperties = properties.map(function(value, key) {
    if (key !== 'anno') {
      return labels[key];
    } else {
      return value;
    }
  });
  return ee.Feature(feature.geometry(), newProperties);
});
1

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.