0

In Google Earth Engine i am trying to find scatter between elevation and occurrence but i am getting common number of array vectors

'''

var data=ee.Image("JRC/GSW1_3/GlobalSurfaceWater").clipToBoundsAndScale(geometry);
var dem=ee.Image("USGS/SRTMGL1_003").clipToBoundsAndScale(geometry);
var mask = data.select(['occurrence']).gt(0);
var data = data.updateMask(mask);
var dem = dem.updateMask(mask);
Map.addLayer(dem,'','dem');
Map.addLayer(data,'','data');
Map.addLayer(mask,'','Mask');
var pixelValsY = data.reduceRegion(
    {reducer: ee.Reducer.toList(), geometry: geometry, scale: 30});
    
var pixelValsX = dem.reduceRegion(
    {reducer: ee.Reducer.toList(), geometry: geometry, scale: 30});
    
var x = ee.List(pixelValsX.get('elevation'));
var y = ee.List(pixelValsY.get('occurrence'));

var chart = ui.Chart.array.values({array: y, axis: 0, xLabels: x});
print(chart);
'''

Erroe msg is 'Error generating chart: xLabels must be the same length as the 1-D vectors from the array.'

please help me out

1 Answer 1

0

Worked when specificying the crs field in .reduceRegion so that the two images are in a common projection. Example:

var pixelValsY = data.reduceRegion(
    {reducer: ee.Reducer.toList(), geometry: geometry, scale: 30});
    
var pixelValsX = dem.reduceRegion(
    {reducer: ee.Reducer.toList(), geometry: geometry, scale: 30, crs: data.projection()});

Alternatively,

var pixelVals = data.addBands(dem).reduceRegion(
    {reducer: ee.Reducer.toList(), geometry: geometry, scale: 30})
var x = ee.List(pixelVals.get('elevation'));
var y = ee.List(pixelVals.get('occurrence'));

In this second example (two less lines of code), it appears that stacking the images sets them to some sort of common projection.

1
  • Thanku, that solves my problem...
    – ashwin
    Commented May 24, 2021 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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