I am trying to perform a supervised image classification to detect water surface area change on two different LANDSAT TM 5 Images, separated by several years. How can I add the numeric property, 'class', to store the binary landcover values water or non-water in my ground truth points? After creating a collection of points on my image, I tried splitting the data into the validation and training sets. The points didn't extract the landcover type into the feature collection properties though. I tried editing the feature collection properties from the settings displayed in the imports section at the very top, but I could not specify a numeric property in order to store landcover type.

Here is a link to my code: https://code.earthengine.google.com/9b906a6e605dcdb08c367480f68a7ff7

  • 1
    Welcome to GIS SE. It would be best to include your code in this post rather than a link to it. – Aaron Feb 15 '17 at 18:59
  • 1
    I wouldn't say 'rather' but 'beside'.. because EE comunity works this way, and the link is useful for us. – Rodrigo E. Principe Jul 25 '17 at 10:53

I'd do something like this:

// Landsat 5 TM Raw Image Collection
var lt5 = ee.ImageCollection("LANDSAT/LT5_L1T");

// Filter by date and location (Landsat Path and Row Designation)
var lakeTiticaca_Early = lt5.filterDate('1985-01-01', '1986-01-01')
.filter(ee.Filter.eq('WRS_PATH', 2))
.filter(ee.Filter.eq('WRS_ROW', 71));

// Selecting Images with least cloud cover
var leastCloud = ee.Image(lakeTiticaca_Early.sort('CLOUD_COVER').first());

// Filter by date and location (Landsat Path and Row Designation)
var lakeTiticaca_Later = lt5.filterDate('2011-01-01', '2012-01-01')
.filter(ee.Filter.eq('WRS_PATH', 2))
.filter(ee.Filter.eq('WRS_ROW', 71));

// Selecting Images with least cloud cover
var leastCloud2 = ee.Image(lakeTiticaca_Later.sort('CLOUD_COVER').first());

// Applying MNDWI Function to Least Cloudy Images 
var mNDWI_Early = leastCloud.expression(
  '(Green - MIR) / (Green + MIR)', {
  'Green': leastCloud.select('B2'),
  'MIR': leastCloud.select('B5')

var mNDWI_Later = leastCloud2.expression(
 '(Green - MIR) / (Green + MIR)', {
 'Green': leastCloud2.select('B2'),
 'MIR': leastCloud2.select('B5')

// Creating an image collection from the MNDWI calculated Images 
var constant1 = ee.Image(mNDWI_Early).select([0],["mNDWI"]);
var constant2 = ee.Image(mNDWI_Later).select([0],["mNDWI"]);

var dif = constant2.subtract(constant1)

var img1 = leastCloud.addBands(constant1)
var img2 = leastCloud2.addBands(constant2)

var final = ee.Image.cat(img1,img2)

//* Supervised Image Classification *//

var training = ee.FeatureCollection([water_nochange, water_gain, water_loss, land_nochange]).flatten()

var sample = final.sampleRegions(training, ["class"], 30)

var trained = ee.Classifier.cart().train(sample, "class")

var classified = final.classify(trained)
Map.addLayer(classified,{min:1, max:4, palette:["#b3b3ff","#0000e6", "#ff0000", "#009900"]},"classified")

You can access the feature collections in the following link: https://code.earthengine.google.com/3f4c2908fcf7c469357b80783f3ef26f

You should mask clouds, use another path/row to include the missing part of the lake, and make more training points. You can also try another classifier like svm, randomForest, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.