I would like to convert polygon (as featurecollection) that has the attribute 'Name' which contains string value of plantation types, namely 'Rubber', 'Mango', 'Coffee'. However, the .reduceToImage
function won't accept string values. Thus, I had to do some workaround by deriving unique numeric id but now I'm stuck.
// Workflow: 1) Import asset, plantation_trial1
// print(plantations);
print(plantations.aggregate_array("Name"));
var plant_field = 'Name'
var all_text = 'what is'
// Function to build states list
var build_select = function(feature_collection, field_name) {
var field_list = ee.Dictionary(feature_collection.aggregate_histogram(field_name))
.keys();
return field_list.map(function(name) {
return ee.Dictionary({'label': name})
}).getInfo();
};
var plant_list = build_select(plantations, plant_field);
print(plant_list);
The 'plant_list' already contains the unique id for each 'Name', but no array or list function worked with the object. So basically, I am trying to have the script automate the extraction of the unique names from the featureCollection and assign each with a unique id. I am also aware that there may be some more efficient alternatives to achieve this, like distinct
. Currently, here is what I got from print()
:
Can anyone give any idea on identifying what object that I have here and what to do with it, please?