I am trying to sample points from a classified raster using Google Earth Engine, but am running into some problems. I developed a script based on the Classification video located here.
Here is a toy script that attempts to randomly sample a stratified raster.
var ROI = ee.Geometry.Rectangle(-82.562342, 35.589551,-82.562342, 35.589551); // define area
var features = [
ee.Feature(ee.Geometry.Rectangle(-82.56123, 35.59053,-82.55213, 35.59674),{class: 0}),
ee.Feature(ee.Geometry.Rectangle(-82.54245, 35.591453, -82.537172, 35.596496),{class:1})
];
var vect = ee.FeatureCollection(features);
print(vect);
Map.addLayer(vect);
var image = vect
.filter(ee.Filter.neq('class', null))
.reduceToImage({
properties: ['class'],
reducer: ee.Reducer.first()
});
Map.addLayer(image,{min:0,max:1,palette: ['black','white']});
var counts = {
0:1000,
1:1000,
};
print(counts)
var stratified = ee.Dictionary(counts)
.map(function(klass,count) {
klass = ee.Number.parse(klass)
var masked = image.updateMask(image.eq(klass))
return masked.addBands(ee.Image.pixelLonLat())
.sample({
region: ROI,
numPixels: 5000,
seed: klass})
.randomColumn('x')
.sort('x')
.limit(ee.Number(count).min(100))
.map(function(f) {
var location = ee.Geometry.Point([f.get('longitude'),f.get('latitude')])
return ee.Feature(location,f.toDictionary())
})
}).values()
stratified = ee.FeatureCollection(stratified).flatten();
print (stratified.reduceColumns(ee.Reducer.frequencyHistogram(),['Class']));
Map.addLayer(stratified);
print(stratified)
Unfortunately, I receive the error message: The default WGS84 projection is invalid for aggregations. Specify a scale or crs & crs_transform.
This error is mentioned on the projections page, but, doesn't offer any real solutions. Does anyone know how to aggregate using the aerial imagery in WGS84 on Google Earth Engine?