TransWikia.com

Spectral signatures chart in Google Earth Engine

Geographic Information Systems Asked by Joost Neujens on April 10, 2021

I have been reading the documentation and some related questions online, but I cannot seem to make it work.
I use Google Earth Engine to access an old Landsat 5 image, and classify later on.

I want to plot the spectral signatures on a chart in earth engine, but I cannot seem to make it work.

This is the error code I keep getting:

Error generating chart: Data column(s) for axis #0 cannot be of type string

As far as I know, all the properties in the FeatureCollection are numeric. I don’t know where the strings might come from.

Can anyone explain what is exactly going wrong?

The code:

// Query satellite image  26.996813, 14.395989
var aoi = ee.Geometry.Rectangle([14.38, 26.98, 14.49, 27.87]);
var collection = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR').filterDate('1995-01-01', '1995-01-30').filterBounds(aoi).filterMetadata('IMAGE_QUALITY', 'equals', 9).select(['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']);

//var rgbImage = collection.sort('CLOUD_COVER').first().select(['B3', 'B2', 'B1']);
var image_ = collection.sort('CLOUD_COVER').first();


// Load training data
var trainData = ee.FeatureCollection('users/jneujens/trainData');

// Property containing land cover labels
var label = 'classname';

// Get training from polygons on image
var training = image_.sampleRegions({
  collection: trainData,
  properties: ['classvalue'],
  scale: 30
});

print(training)


// Graph of spectral signatures training data
var options = {
  title: 'Landsat 5 surface reflectance spectral signatures',
  hAxis: {title: 'Wavelength (micrometers)'},
  vAxis: {title: 'Reflectance'},
  lineWidth: 1,
  pointSize: 4,
  series: {
    0: {color: 'grey'}, // impervious
    1: {color: 'green'}, // vegetation
    2: {color: 'red'}, // soil
}};

// Define a list of Landsat 8 wavelengths for X-axis labels.
var wavelengths = [0.47, 0.56, 0.66, 0.83, 1.56, 2.2, 11.4];

// Create the chart and set options.
var spectraChart = new ui.Chart.image.regions(
    image_, training, ee.Reducer.mean(), 30, 'classvalue', wavelengths)
        .setChartType('ScatterChart')
        .setOptions(options);

print(spectraChart)

2 Answers

Try providing trainData as the regions argument to ui.Chart.image.regions() instead of training. The .sampleRegions() step is unnecessary and it may be altering your original collection.

Answered by Justin Braaten on April 10, 2021

try using remap function to convert the class values from string to integers

Answered by Noufia on April 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP