In this exercise, we will try to sample a composite image of the Landsat with the landcover feature collection that we have. The full code can be found here.
The Feature Collection has the following integer assigned for ‘landcover’ column.
0 -> urban
1 -> vegetation
2 -> water
- We will use Landsat.simpleComposite method of the ee.Algorithms object to create the composite. Get the Landsat image collection and apply the simpleComposite() method to make the cloud-free composite.
// 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 });
- Next, get the feature collection that you want to sample.
var newfc = ee.FeatureCollection("users/biplov/blog/trainingPoints4Sampling");
- Since the ‘landcover’ column or property stores the landcover information, we will use that. And then we will use the sampleRegions method to do the sampling.
// The name of the property on the points storing the class label. var classProperty = 'landcover'; // Sample the composite to generate training data. Note that the // class label is stored in the 'landcover' property. var sampledPoints = composite.sampleRegions({ collection: newfc, properties: [classProperty], scale: 30, geometries: true });
- Finally, you can export the sampled points to your assets, so you can use it later for classification purpose.
Export.table.toAsset(sampledPoints, 'sampledPoints', 'users/biplov/blog/sampledPoints');
Leave a Reply