TransWikia.com

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

Geographic Information Systems Asked by Nimisha Wagle on March 2, 2021

When I try to create chart by bands and image spectra i get "Error generating chart: Data column(s) for axis #0 cannot be of type string"

// Plot band values at points in an image.
var L8_SR = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');

var COLOR = {
  built_up: 'ff0000',
  grassland: '00ff00',
  forest: '228B22',
  water: '0000ff',
  snow: 'add8e6',
  rocky: '808080',
  cultivation:'ffff00'
};

// 7 known locations.
var built_up = ee.Feature(
    ee.Geometry.Point(83.978710, 28.3202722), {'label': 'built_up'});
var grassland = ee.Feature(
    ee.Geometry.Point(84.008199, 28.218142), {'label': 'grassland'});
var forest = ee.Feature(
    ee.Geometry.Point(84.2250, 28.371391), {'label': 'forest'});
var water = ee.Feature(
    ee.Geometry.Point(83.947601, 28.215001), {'label': 'water'});
var snow = ee.Feature(
    ee.Geometry.Point(83.895411, 28.588669), {'label': 'snow'});
var rocky = ee.Feature(
    ee.Geometry.Point(84.042354, 28.523533), {'label': 'rocky/Barren'});
var cultivation = ee.Feature(
    ee.Geometry.Point(84.085761,28.170022), {'label': 'cultivatiom'});

var kaskiPoints = ee.FeatureCollection([built_up, grassland, forest,water,snow,rocky,cultivation]);
var landsat8SR = L8_SR.filterBounds(kaskiPoints);

var KaskiImage = ee.Image(landsat8SR.first());

// Select bands B1 to B7.
KaskiImage = KaskiImage.select(['B[1-7]']);

var bandChart = ui.Chart.image.regions({
  image: KaskiImage,
  regions: kaskiPoints,
  scale: 30,
  seriesProperty: 'label'
});
bandChart.setChartType('LineChart');
bandChart.setOptions({
  title: 'Landsat 8 band values at 7 classes in kaski district',
  hAxis: {
    title: 'Band'
  },
  vAxis: {
    title: 'Reflectance'
  },
  lineWidth: 1,
  pointSize: 4,
  series: {
    0: {color: COLOR.built_up},
    1: {color: COLOR.grassland},
    2: {color: COLOR.forest},
    3: {color: COLOR.water},
    4: {color: COLOR.snow},
    5: {color: COLOR.rocky},
    6: {color: COLOR.cultivation}
  }
});

// From: https://landsat.usgs.gov/what-are-best-spectral-bands-use-my-study
var wavelengths = [.44, .48, .56, .65, .86, 1.61, 2.2];

var spectraChart = ui.Chart.image.regions({
  image: KaskiImage,
  regions: kaskiPoints,
  scale: 30,
  seriesProperty: 'label',
  xLabels: wavelengths
});
spectraChart.setChartType('LineChart');
spectraChart.setOptions({
  title: 'Landsat 8 Surfacereflectance spectra at 7 classes in kaski district',
  hAxis: {
    title: 'Wavelength (micrometers)'
  },
  vAxis: {
    title: 'Reflectance'
  },
  lineWidth: 1,
  pointSize: 4,
  series: {
    0: {color: COLOR.built_up},
    1: {color: COLOR.grassland},
    2: {color: COLOR.forest},
    3: {color: COLOR.water},
    4: {color: COLOR.snow},
    5: {color: COLOR.rocky},
    6: {color: COLOR.cultivation}
  }
});

print(bandChart);
print(spectraChart);

code link : https://code.earthengine.google.com/c24c20cbf4b0b9a2e820e541f82acc6b

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