Google Earth Engine: I'm getting the error "Property 'x' of feature 'y' is missing" when classifying an image collection

129 Views Asked by At

I am attempting to classify each image in an imageCollection using Landsat 7 data. When I classify a single image from this collection everything works great, and I am getting great accuracies. When I try to map my classifier over my image collection, I am getting the error "Property 'B1' of feature 'LE07_066018_20220603' is missing" (LE07_066018_20220603 is the first image in the collection), as if there is no band data. Here is my code:

//identify my classes for classification
var classes = ee.FeatureCollection('projects/ee-masonbull/assets/allClasses');
var wtrshd = ee.FeatureCollection('users/masonbull/nj_wtrshd_ocean');
//set start and end date to get imagery
var date_i = '1999-03-01'; // set initial date (YYYY-MM-DD)
var date_f = '2023-06-30'; // Set final date (YYY-MM-DD)

//grab landsat 7 data
var l7 = ee.ImageCollection("LANDSAT/LE07/C02/T1_RT")
  .filterDate(date_i, date_f)
  .filter(ee.Filter.calendarRange(5, 10, 'month'))
  .filterBounds(ee.Geometry.Point(-148.8904089876178,60.362297433254604))
  .select('B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8')
  .filter(ee.Filter.lte('CLOUD_COVER_LAND', 25));

//create a function to clip all of the imagery to the watershed boundaries
var clipping = function(image) {
  return image.clip(wtrshd);
};

var l7_clip = l7.map(clipping);
print(l7_clip);

//define bands and a label for the sampling
var l7Bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8'];

var label = 'Class';

//create a funciton to sample each image in the imageCollection
var sampleCollectionFunc = function(image){
  var sampler =  image.sampleRegions({
  'collection': classes,
  'properties': [label],
  'scale': 30,
  'geometries': true
});
return sampler;
};

var sampleCollection = l7_clip.map(sampleCollectionFunc);
print('sampleCollection', sampleCollection);

//add random column to sampled images (now featureCollections)
var addRandomFunc = function(FeatureCollection){
  var random = ee.FeatureCollection(FeatureCollection).randomColumn({'seed': 0, 'distribution': 'uniform'});
  return ee.FeatureCollection(random).set('band_order', ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8']);
};


var randomCollection = sampleCollection.map(addRandomFunc);

//create training data from random column
var createTraining = function(in_FeatureCollection){
  var filter = ee.FeatureCollection(in_FeatureCollection).filter(ee.Filter.lt('random', 0.8));
  return filter;
};
var training = randomCollection.map(createTraining);

//train the classifier, in this case an SVM
var classifierSVM = ee.Classifier.libsvm({'decisionProcedure': 'Voting',
 'svmType': 'C_SVC', 
 'kernelType': 'RBF', 
 'shrinking': true,
 'gamma': 0.00125,
 'cost': null}).train({
 'features': training,
 'classProperty': label,
 'inputProperties': l7Bands,
 'subsamplingSeed':0
 });
 
//create a function to map over the feature and imageCollections to classify them 
var classSamp = function(FeatureCollection){
  return ee.FeatureCollection(FeatureCollection).classify(classifierSVM, 'predicted');
};
var model = ee.FeatureCollection(sampleCollection).map(classSamp);
print('model', model);


var imageClassifier = function(image){
  return image.classify(classifierSVM, 'predicted');
};
var classVisParams = {min: 0, max: 5, 'palette': ['062EF5', 'E8EAF5', 'E5330C', '0E5B07', '938507', '00EF12']};


var classifiedImages = l7_clip.map(imageClassifier);
print('classifiedImages', classifiedImages);



I am still pretty new to GEE, so ANY improvement will be greatly appreciated. I have never posted on a forum like this before so please let me know how to improve my question! Here is a link to the code: https://code.earthengine.google.com/2eca3bc40a31d077c163ce51b00202ca

I have tried a few different methods of creating a function to map over the image collection with my classifier, but I keep getting the same error. I have tried nesting functions, but I am not skilled enough to really know how they are working. With one image (the first image) I can use all of the code available above to classify it correctly, the issue seems to only arise when mapping functions.

0

There are 0 best solutions below