I am trying to perform landcover classification of Shanghai using JavaScript in Google Earth Engine. I am a complete beginner at this and I have been going through many tutorials trying to figure things out. My problem is that many of these tutorials are aimed at Landsat 8 but I need to use Landsat 7 and it covers the time period I need.

I have made my training points and now need to create the training data, so far my code is as follows:

//filter image collection
* Function to mask clouds based on the pixel_qa band of Landsat SR data.
* @param {ee.Image} image Input Landsat SR image
 * @return {ee.Image} Cloudmasked Landsat image
var cloudMaskL457 = function(image) {
  var qa = image.select('pixel_qa');
  // If the cloud bit (5) is set and the cloud confidence (7) is high
  // or the cloud shadow bit is set (3), then it's a bad pixel.
  var cloud = qa.bitwiseAnd(1 << 5)
                  .and(qa.bitwiseAnd(1 << 7))
                  .or(qa.bitwiseAnd(1 << 3));
  // Remove edge pixels that don't occur in all bands
  var mask2 = image.mask().reduce(ee.Reducer.min());
  return image.updateMask(cloud.not()).updateMask(mask2);

var dataset = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
                  .filterDate('2013-01-01', '2015-12-31')

var visParams = {
  bands: ['B3', 'B2', 'B1'],
  min: 0,
  max: 3000,
  gamma: 1.4,
Map.setCenter(121.51520494843749,31.22304570235914, 10);
Map.addLayer(dataset.median(), visParams);

//merge the feature collections
var newfc = Urban.merge(Water).merge(Vegetation);
//print (newfc);

//create training data by overlaying the training points on the image
var bands = ['B2', 'B3', 'B4', 'B5', 'B6_VCID_1', 'B6_VCID_2', 'B7'];
var training = image.select(bands).sampleRegions({
    collection: newfc, 
    properties: ['landcover'], 
    scale: 30

When I run this it says that image is not defined (after var training), which is true, I have not defined it, but when I try other things (for instance cloudMaskL457.select) it says that cloudMaskL457.select is not a function.

I don't know how to get past this, please help!

Your Answer

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

Browse other questions tagged or ask your own question.