0

I want to do random forest classification. I prepared a point shape file with training sample outside GEE, the true land cover class being in the field code. Then I imported the shapefile in GEE (as training_shape) and wanted to sample a raster image (input_img_m) in order to get the raster values for each point and thus generate training sample for classification.

However, I am not sure which tool to use. I tried with .sampleRegions. I know this is working exactly I want it with polygons and I hoped it will work with point as well. But after 20 min of processing I get error: Error: Unable to export features with null geometry.

This is part of my script:

var training = input_img_m.sampleRegions({
  // Get the sample from the point FeatureCollection.
  collection: training_shape,
  // We'll classify on 'code"
  properties: ['code'],
  // Set the scale to get Sentinel-2 pixels.
  scale: 10,
  tileScale: 4
});


Export.table.toAsset({
  collection: training,
  description:'exportToTableAsset',
  assetId: 'samples',
});

My question is what is the better way to use training sample shape file for classification in GEE if the geometry of the shapes is point?

2

sampleRegions() will by default omit the geometries, and like you might guess from the error message, Export.table.toAsset() expects the features to contain geometries. You can explicitly include the geometries by setting the geometries property in sampleRegions() to true.

var training = input_img_m.sampleRegions({
  collection: training_shape,
  properties: ['code'],
  scale: 10,
  tileScale: 4,
  geometries: true
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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