2

I am classifying rice for the Red River Delta with 2 class: class 0: Rice class 1: Not rice

I used svm classifier algorithm. However, after running the code, the classifier operated for a long time without results. Here is my code : Link: https://code.earthengine.google.com/f70f6ae7d54a428829a84cbc9d27ea3b

Code:

//Load 1 shapefile red river delta
var dbsh_shape = ee.FeatureCollection('users/chungpd/DBSH_Shape');
Map.centerObject(dbsh_shape);
Map.addLayer(dbsh_shape);

// Use these bands for prediction.
var bands = ['VV', 'VH'];

// Load an imagecollection over a portion of Red river delta
var img1 = ee.ImageCollection('COPERNICUS/S1_GRD')
  .filterDate('2017-01-03', '2017-01-18')
  .filterBounds(dbsh_shape);

// Cut img1 according to "dbsh_shape" shapefile
var img2 = img1.map(function(image) {return image.clip(dbsh_shape);});

// Mosaic img2
var image = img2.mosaic();
print (image);

// Load training polygons from a Fusion Table.
// The 'class' property stores known class labels.
var polygons = ee.FeatureCollection('ft:1fxOJdG56CUWXy7MWi4KPeCAvKYC4YHFzMbRPU7S3');

// Get the values for all pixels in each polygon in the training.
var training = image.sampleRegions({
  // Get the sample from the polygons FeatureCollection.
  collection: polygons,
  // Keep this list of properties from the polygons.
  properties: ['class'],
  // Set the scale to get Landsat pixels in the polygons.
  scale: 10
});

// Create an SVM classifier with custom parameters.
var classifier = ee.Classifier.svm({
  kernelType: 'RBF',
  gamma: 0.5,
  cost: 10
});

// Train the classifier.
var trained = classifier.train(training, 'class', bands);

// Classify the image.
var classified = image.classify(trained);

// Create a palette to display the classes.
var palette =['00FF00', 'DD0000'];

// Display the classification result and the input image.
//Map.addLayer(image, {bands: ['VV', 'VH'], max: 0.5, gamma: 2});
//Map.addLayer(classified, {min: 0, max: 10, palette: palette}, 'Isrice');
Map.setCenter(105.96999, 20.90339, 7);
//Map.centerObject(image, 10);
Map.addLayer(image, {bands: ['VV', 'VH'], max: 0.4}, 'image');
Map.addLayer(classified, {min: 0, max: 1, palette: ['00FF00', 'DD0000']},
  'classification');

This is the error:

classification error: Layer error: Computation timed out.
  • Please include the code as well as errors directlly into the body of the question instead of using images. – Kersten Jan 11 '18 at 7:41
  • Additionally you would need to share/grant permissions on your FusionTable as well as on the asset dbsh_shape. – Kersten Jan 11 '18 at 7:44
  • Thanks @Kersten, after I replace scale 10 with 15 or 20, I got the results, I am wondering why it didn't come out the output when replacing the scale 10 but while replacing 15 or 20, It did. and which range of scale for sentinel 1A? – Chung Jan 11 '18 at 10:24
  • @Kersten, I have shared the dbsh_shape and also the training data. Please check it, thank you very much. – Chung Jan 11 '18 at 10:36
1

Scale refers to the pixel resolution in meters.

So you have reduced the spatial resolution when you replaced scale 10 with 15 or 20.

I think it is why you got the result.

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.