Monday 25 February 2019

clustering - Obtaining "nClusters" value in Google Earth Engine


After training the kmeans model, how can i obtain the number of classes of the model? i've tried with get(), getInfo() and doesnt work.


enter image description here


https://code.earthengine.google.com/ff0c7bd8102d17b2d267b96bd070342a


Value that must to be extracted in "//var to_print_2 = clusterer.get('nClusters')"


// STEP 1: Import image we wish to classify
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1')

// Remove the clouds
var cloud_free = ee.Algorithms.Landsat.simpleComposite({

collection: l8.filterDate('2018-01-01', '2018-12-31'),
asFloat: true
})

// STEP 2: Draw your box which you will sample from!
// Make the training dataset.
var training = cloud_free.sample({
region: geometry,
scale: 30,
numPixels: 5000

});

// Step 3: Create the clusterer and train it, play around with
// number of classes
var clusterer = ee.Clusterer.wekaKMeans(3).train(training);

print('clusterer',clusterer instanceof ee.ComputedObject);

var to_print = clusterer.getInfo();


print('clusterer_info',clusterer.toString());

print(typeof clusterer);

var clusterer_list = ee.List(clusterer);

print('clusterer_list',clusterer_list);

print(typeof clusterer_list);



//var to_print_2 = clusterer.get('nClusters');

//print(to_print_2);

//var to_print_3 = clusterer.Filter.filterMetadata('nClusters','equals',3);

//print(to_print_3);

// Step 4: Classify our image

var classified = cloud_free.cluster(clusterer);
print(classified);
var cluster_1 = classified.eq(0);
print('min',cluster_1);


// Display
Map.setCenter(-122.31040963183364, 37.782065864682096, 11)
Map.addLayer(classified.randomVisualizer(), {}, 'clusters');


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...