The full code for classification after obtaining sample points is here. The full code for classification with sample points generated on the fly is here.

Note: This is a very simple method for generating Landcover maps meant for showing the basic workflow for generating Landcover maps. You can use more sophisticated algorithms like Random Forest, or SVM, or some deep learning architecture to generate the maps. Together with that, you can use various indices like NDVI, EVI, NDSI, etc. with other related attributes like distance to coast, distance to road, etc. to sample the training points.

  1. Import the sampled points that we get after exporting the point sampling. See this post for more detail on how to get those sampled points.
    var sampledPoints = ee.FeatureCollection("users/biplov/blog/sampledPoints");
  2. Load the composite or the image that you want to classify.
    // Load the Landsat 8 image collection and filter by date.
    var landsatCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1').filterDate('2018-01-01', '2018-12-31');
    // Make a cloud-free composite.
    var composite = ee.Algorithms.Landsat.simpleComposite({
      collection: landsatCollection,
      asFloat: true
  3. In this map, we implement the CART (Classification and Regression Trees) for classification purpose. Read more about the CART here. We will use the default parameters. We will train the classifier over to the available bands, which can be obtained by using bandNames() method. Make sure to tune various parameters to get the best result. The landcover is the column that stores the information about various landcover class. Here, in this case, the values and their associated class are:
    0 -> urban
    1 -> vegetation
    2 -> water

    var bands = composite.bandNames();
    // Train a CART classifier with default parameters.
    var trained = ee.Classifier.cart().train(sampledPoints, 'landcover', bands);
  4. Lastly, classify the composite image with the same bands that we used for training purpose in above steps.
    var classified =;