How to easily create Training data in Google Earth Engine

Training data is needed as a sample or reference for the use of the Google Earth engine. Its function is very useful as input data in a mapping data analysis process. For example, if we want to calculate how much area is covered by oil palm plants, then we need training data in the form of a data set of sample points and polygons of areas planted with oil palm. The next step is for the Google Earth engine to search for land areas according to the training data we input.

Steps to create training data

In this tutorial, I will write how to create training data on google earth directly, not other software. first, open the google earth engine. if you can’t, read the basic google earth engine article.

how to create data training

The next step is to import images from the satellite, preferably using images from the period during which the research will be conducted. For example, we will calculate the area of oil palm land in August, so we take pictures in that month. Although this step is not mandatory because the training data set that will be taken later is the point coordinates, it will help visually compare the actual data in the field against the training data that we will compile.

var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
var indonesia = countries.filter(ee.Filter.eq('country_na', 'Indonesia'));
Map.centerObject(indonesia, 8);

function maskS2clouds(image){
    return image.updateMask('QA60').eq(0))}

var s1_collection = ee.ImageCollection("COPERNICUS/S2_SR");

var s1_composite_masked = s1_collection.filterBounds(indonesia) 

var vis = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 1250};
Map.addLayer(s1_composite_masked, vis, 'Sentinel 2 2019 Masked');

The code above calls the image from Sentinel 2 in 2019. but the image is a lot covered by clouds, so I made a custom with a special area in the city of Medan, as follows (first I imported a small map from Google Earth with the variable name = table):

var contoh = table ;
Map.centerObject(contoh, 13);
var vis = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 1250};
Map.addLayer(contoh, vis);
data training gee

Next, we zoom to get the region that will be the training data. For the time being, we disable layer 1 because the shading makes the image less clear.

data validasi gee

I will create training data for the collection of coconut trees in the image above. The way is to create a point by clicking Add a marker. Note its position in the image below:

data training.

Then we click geometry and click the gear sign. We change it according to our needs. Don’t forget to add a property as a meta material from this collection of points. For the first point, make the property value zero.

how to create training data

Don’t forget to change import to geometry with featuterColection (according to the picture above). Click OK, and we click the object on the map that indicates “class is 0”. For example, this time I intend to make class = 0 the point of the coconut tree. then I make a point on the map right on the coconut tree. Look at the picture:

create data point

Please note that in the import section, it will automatically add a variable called coconut according to the layer we create. I managed to create 21 points at this location.

Next, we create another layer with a class=1 value; we can name it the rice field layer, for example.

layer sawah dan kelapa

I already have training data consisting of coconut data and rice field data. I added one more with the name forest. then I want to combine the training data into one, and of course the property in it also merges into class = 0 and class = 1.

The way is to use the script below:

var training = forest.merge(kelapa)
  collection: training,
  description: 'datalatihan',
  assetId: 'datalatihan'

This script combines the three training data sets (forest, coconut, and rice fields) to be imported into the GEE asset and can be used for more complex analysis input with the asset name datalatihan. then just follow the commands in GEE, including clicking on tasks to upload it to the GEE asset.

Thank you.

Note: The difference between training data and validation data is that training data is in the form of points, while validation data is in the form of polygons. The method is the same as in this article.


Leave a Reply

Your email address will not be published. Required fields are marked *