0

I'm trying to implement algorithm on Earth Engine Code to predict cultivated area. This is my code:

var landsatCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1')
    .filterDate('2017-01-01', '2017-12-31');

// Make a cloud-free composite.
var composite = ee.Algorithms.Landsat.simpleComposite({
  collection: landsatCollection,
  asFloat: true
});

// Merge the three geometry layers into a single FeatureCollection.
var newfc = urban.merge(vegetation).merge(water).merge(urban).merge(fields);

// Use these bands for classification.
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
// The name of the property on the points storing the class label.
var classProperty = 'landcover';

// Sample the composite to generate training data.  Note that the
// class label is stored in the 'landcover' property.
var training = composite.select(bands).sampleRegions({
  collection: newfc,
  properties: [classProperty],
  scale: 30
});

// Train a CART classifier.
var classifier = ee.Classifier.smileCart().train({
  features: training,
  classProperty: [classProperty],
});
// Print some info about the classifier (specific to CART).
print('CART, explained', classifier.explain());

// Classify the composite.
var classified = composite.classify(classifier);
Map.centerObject(newfc);
Map.addLayer(classified, {min: 0, max: 3, palette: ['red', 'blue', 'green','yellow']});

// Optionally, do some accuracy assessment.  Fist, add a column of
// random uniforms to the training dataset.
var withRandom = training.randomColumn('random');

// We want to reserve some of the data for testing, to avoid overfitting the model.
var split = 0.7;  // Roughly 70% training, 30% testing.
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));

// Trained with 70% of our data.
var trainedClassifier = ee.Classifier.smileCart().train({
  features: trainingPartition,
  classProperty: classProperty,
  inputProperties: bands
});

// Classify the test FeatureCollection.
var test = testingPartition.classify(trainedClassifier);

// Print the confusion matrix.
var confusionMatrix = test.errorMatrix(classProperty, 'classification');
print('Confusion Matrix', confusionMatrix);

I am getting these errors:

  • CART, explained Dictionary (Error) Property 'landcover' of feature '1_1_1_1_0_0' is missing.
  • Confusion Matrix ConfusionMatrix (Error) Property 'landcover' of feature '1_1_1_1_1_0' is missing.
  • Layer 1: Layer error: Property 'landcover' of feature '1_1_1_1_0_0' is missing.

Give me some suggestions to resolve these errors.

1 Answers1

0

The error seems like in line 11, var newfc = urban.merge(vegetation).merge(water).merge(urban).merge(fields);

  1. Make sure urban and others are a FeatureCollection from Configure geometry import tool.
  2. Add Property 'landcover' and value 1 for urban, 2 for water and so on.

you can check print(newfc) and look at the properties and check for feature '1_1_1_1_0_0'

I have attached the image.configure geometry point

Aung_KK
  • 1
  • 1