i try to perform a supervised classification with Google Earth Engine based on NAIP: National Agriculture Imaginary Progamm orthofotos. These images have a resolution of 1m in 4 Bands (R,G,B,N). I am looking for a classification in Vegetation, Impervious, Water.
I followed the various tutorials on Sentinel-Data. I sampled training data as polygons for the different classes and safed them as FeatureCollections with properties and values. Then I merged them into one collection and continued with sampleRegions. Then i start building the training-process and further to classify the whole image.
Unfortunately i get the Error: "orthofoto.sampleRegions is not a function"
My code works with Sentinel-Data but it happens to not work with the orthofotos. I Does anyone know how a classification should be done?
This is my work so far:
// Imports: FeatureCollections for training data, Property: 'landcover', Value: [0,1,2]
// vegetation: FeatureCollection, landcover:0
// impervious: FeatureCollection, landcover:1
// water: FeatureCollection, landcover:2
// Function for clipping image
var clipcol = function(image) {
var clipimage = image.clip(geometry)
return clipimage
}
// Import of NAIP-Orthofoto
var dataset = ee.ImageCollection('USDA/NAIP/DOQQ')
.filter(ee.Filter.date('2017-01-01', '2018-12-31'))
.filterBounds(geometry)
.map(clipcol)
// Just get the second image of the collection
var listOfImages = dataset.toList(dataset.size());
var orthofoto = listOfImages.get(1)
// True Color Visualisation
var trueColor = dataset.select(['R', 'G', 'B']);
var trueColorVis = {
min: 0.0,
max: 255.0,
};
Map.addLayer(trueColor, trueColorVis, 'Orthofoto');
// Band selection and merge of the 3 FeatureCollection
var bands = ['R', 'G', 'B', 'N'];
var merged_collection = impervious.merge(vegetation).merge(water)
// Sample Regions (Error!)
var training = orthofoto.sampleRegions({
collection: merged_collection,
properties: ['landcover'],
scale: 1
})
var classifier = ee.Classifier.smileRandomForest(10).train({
features: training,
classProperty: 'landcover',
inputProperties: bands
})
var classified = dataset.select(bands).classify(classifier)
Map.addLayer(classified, {min:0, max:2, palette: ['green','red','blue']},
"classified image")