2

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")
1

1 Answer 1

4

Your property 'orthofoto' is a computedObject, not an image. You can specify the property as an image by:

var orthofoto = ee.Image(listOfImages.get(1))

Alternatively, if it works for your project, you can take the mean of the dataset using dataset.mean() and use that for sampling. Of course, this means that you're sampling across the entire date period and not just the second image in the collection.

1
  • Hey! Thank you for your response, it solved my problem and works now fine! Have a great new year!
    – maniiko
    Jan 4, 2022 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.