You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Define the feature names (modify as needed)
var features = ['Excellent', 'Good', 'Moderate', 'Fair', 'Poor'];
// Define the image collections with a list (replace with your actual collections)
var imageCollections = [ceei2003, ceei2011, ceei2023];
// Function to create a single image collection with bands from each year
function combineCollections(image) {
var year = image.date().format('YYYY');
return image.select(features).rename(features.map(function(f) { return f + '_' + year; }));
}
// Combine image collections into a single one with renamed bands
var imageCollection = ee.ImageCollection(imageCollections).map(combineCollections);
// Function to add year as a feature
function addYear(image) {
var date = image.date();
var years = date.difference(ee.Date('1970-01-01'), 'year');
return image.addBands(years);
}
// Apply functions and filter to your area of interest
var imageCollection = imageCollection
.map(addYear)
.filterBounds(your_geometry); // Replace with your area of interest geometry
// Define Random Forest training data (modify as needed)
var trainingData = imageCollection.filterDate('2003-01-01', '2011-12-31'); // Adjust training period
// Function to define a Random Forest classifier (adjusted for API compatibility)
function classify(image) {
var trainingFeatures = trainingData.select(features.concat(['year']));
var trainingLabels = trainingData.select('classification'); // Replace 'classification' with your actual label band
var classifier = ee.Classifier.smileRandomForest({
numberOfTrees: 100 // Adjust number of trees
});
// Apply Random Forest classification
var classifiedCollection = imageCollection.map(classify);
// Function to predict future year (modify year as needed)
function predict(classifiedImage, year) {
// Set the predicted year as a property to the classified image
return ee.Image(classifiedImage).set('predicted_year', year);
}
// Predict for a future year (replace 2025 with your desired year)
var predictedImage = classifiedCollection.map(predict.bind(null, 2025));
// Select the first image from the predicted collection
var predictedImageFirst = predictedImage.first();
// Predict for a future year (replace 2025 with your desired year)
var predictedImage = classifiedCollection.map(predict.bind(null, 2025));
print(predictedImageFirst);
// // Add the predicted image to the map
// Map.addLayer(predictedImageFirst, {bands: ['Excellent_2025', 'Good_2025', 'Moderate_2025'], min: 0, max: 1, gamma: 1.4}, 'Predicted Image');
// // Display the map
// Map.centerObject(your_geometry, 10); // Center the map on your geometry
// // Map.addLayer(your_geometry, {}, 'Area of Interest'); // Add a layer for visualization
// Define the feature names (modify as needed)
var features = ['Excellent', 'Good', 'Moderate', 'Fair', 'Poor'];
// Define the image collections with a list (replace with your actual collections)
var imageCollections = [ceei2003, ceei2011, ceei2023];
// Function to create a single image collection with bands from each year
function combineCollections(image) {
var year = image.date().format('YYYY');
return image.select(features).rename(features.map(function(f) { return f + '_' + year; }));
}
// Combine image collections into a single one with renamed bands
var imageCollection = ee.ImageCollection(imageCollections).map(combineCollections);
// Function to add year as a feature
function addYear(image) {
var date = image.date();
var years = date.difference(ee.Date('1970-01-01'), 'year');
return image.addBands(years);
}
// Apply functions and filter to your area of interest
var imageCollection = imageCollection
.map(addYear)
.filterBounds(your_geometry); // Replace with your area of interest geometry
// Define Random Forest training data (modify as needed)
var trainingData = imageCollection.filterDate('2003-01-01', '2011-12-31'); // Adjust training period
// Function to define a Random Forest classifier (adjusted for API compatibility)
function classify(image) {
var trainingFeatures = trainingData.select(features.concat(['year']));
var trainingLabels = trainingData.select('classification'); // Replace 'classification' with your actual label band
var classifier = ee.Classifier.smileRandomForest({
numberOfTrees: 100 // Adjust number of trees
});
return image.select(features.concat(['year']))
.classify(classifier.train(trainingFeatures, trainingLabels));
}
// Apply Random Forest classification
var classifiedCollection = imageCollection.map(classify);
// Function to predict future year (modify year as needed)
function predict(classifiedImage, year) {
// Set the predicted year as a property to the classified image
return ee.Image(classifiedImage).set('predicted_year', year);
}
// Predict for a future year (replace 2025 with your desired year)
var predictedImage = classifiedCollection.map(predict.bind(null, 2025));
// Select the first image from the predicted collection
var predictedImageFirst = predictedImage.first();
// Predict for a future year (replace 2025 with your desired year)
var predictedImage = classifiedCollection.map(predict.bind(null, 2025));
print(predictedImageFirst);
// // Add the predicted image to the map
// Map.addLayer(predictedImageFirst, {bands: ['Excellent_2025', 'Good_2025', 'Moderate_2025'], min: 0, max: 1, gamma: 1.4}, 'Predicted Image');
// // Display the map
// Map.centerObject(your_geometry, 10); // Center the map on your geometry
// // Map.addLayer(your_geometry, {}, 'Area of Interest'); // Add a layer for visualization
Link: https://code.earthengine.google.com/bbf8cde3b66c29678ee60279f35d0230
when i run the code it shows
Image (Error)
String: Unable to convert object to string. Please help
The text was updated successfully, but these errors were encountered: