I have a Sentinel 2 satellite image and am rating it. I already classified all the native vegetation separated into a shapefile. Now I need to classify the anthropic uses, I would like the GEE to classify this image but ignore the vegetation areas indicated in the shapefile, how could I do this. I tried this solution Using FeatureCollection to mask an image in Google Earth Engine?, bbut I couldn't replicate,because GEE says "ifc is not a function". How to make it?
Ny code:
var img1 = ee.ImageCollection("COPERNICUS/S2_SR")
.filterMetadata('MGRS_TILE', 'equals', '21KYT')
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than', 1)
//.filterMetadata('CLOUD_COVER', 'less_than', 0.01)
.filterDate('2020-01-01','2020-12-26')
.select(['B4', 'B3', 'B2'])
.median();
var img2 = img1.clip(table)
//add a região de interesse
var regiao = img1;
//add info iniciais para o treinamento
var treinamento = img1.sample({
region: table,
scale: 10,
numPixels: 450,
});
//var agrupamento = ee.Clusterer.wekaLVQ(9, 0.1).train(treinamento);//6 6,1
//var agrupamento2 = ee.Clusterer.wekaLVQ(9, 0.7).train(treinamento);//6 6,1
var agrupamento3 = ee.Clusterer.wekaLVQ(9, 1).train(treinamento);//6 6,1
//var resultado = img1.cluster(agrupamento);
//var resultado2 = img1.cluster(agrupamento2);
var resultado3 = img1.cluster(agrupamento3);
//Map.addLayer(resultado, {min:0, max: 6, palette: ['#8668d7', '#03a2b8', '#607f72', 'red', '#5d8f5b', '#e624b6', ]}, 'Resultado_Unsup');
//Map.addLayer(resultado2, {min:0, max: 6, palette: ['#8668d7', '#03a2b8', '#607f72', 'red', '#5d8f5b', '#e624b6', ]}, 'Resultado_Unsup2');
Map.addLayer(resultado3, {min:0, max: 6, palette: ['#8668d7', '#03a2b8', '#607f72', 'red', '#5d8f5b', '#e624b6', ]}, 'Resultado_Unsup3');
//Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], min:178, max:1110}, 'S2');
// Export the image, specifying scale and region.
Export.image.toDrive({
image: resultado3.float(),
description: 'unsup_Sentinel_9',
scale: 10,
region: table,
folder: 'GEE_Ceroula_3',
//crs: 'EPSG:32721'
});
var styling = {color: 'yellow', fillColor: '00000000'};
Map.addLayer(table.style(styling));
Map.centerObject(table, 10);
Best Answer
The solution for your problem lies in a three-step processing:
Small note: It is important to remember that the vegetation class in each pixel will be a value, and not a string.
After these three steps, the rest of your training code will work just fine.
Here is an example which you can check it out:
https://code.earthengine.google.com/9fc631eba38a3f6d7e16deffb0b80fc2
Below I paste the respective link's code: