0

I am working with a featureCollection of river data which is segmented by river reaches (there are hundreds within a few km). This collection includes data of reach length and reach discharge. I am trying to plot a histogram or column chart where the x-axis represents reach length and the y-axis the reach discharge.

So far I've managed to build a column chart but where length is represented by individual columns rather than grouped by buckets,

enter image description here

or to build a histogram for reach length and reach discharge separately.

enter image description here

What I would really like is to be able to group hAxis values into buckets for the first chart, but I don't know if it is possible with GEE:

enter image description here

This is the code I've written (studyArea can be any random polygon):

var dataRivers = ee.FeatureCollection("WWF/HydroSHEDS/v1/FreeFlowingRivers");
var dataRiversStudy = dataRivers.filterMetadata('INC', 'equals', 1).filterBounds(studyArea);

print('dataRiversStudy:',dataRiversStudy);

Map.addLayer(dataRiversStudy,{color: "darkblue",width: 2.0},'Rivers');

var chart = ui.Chart.feature.byFeature({features:dataRiversStudy, xProperty:'LENGTH_KM', yProperties:['DIS_AV_CMS']})
                .setChartType('ColumnChart')
                // .setOptions({bucketSize:2,maxBuckets:10}); // This does nothing

print(chart);

var chart2 = ui.Chart.feature.byFeature({features:dataRiversStudy, xProperty:'LENGTH_KM', yProperties:['DIS_AV_CMS']})
                .setChartType('Histogram');

print(chart2);

And here is the link to the code: https://code.earthengine.google.com/4cc589ee05c037494eb20839402096da

1 Answer 1

2

It's not quite clear if you want two histograms or some kind of a 2D/3D chart. But based on the rest of the question, I think the fixed2DHistogram reducer might be able to produce the values you want. But there is no chart type that will display that, since it's essentially 3D data.

var studyArea = ee.Geometry.Rectangle([31, 46, 35, 48])

var dataRivers = ee.FeatureCollection("WWF/HydroSHEDS/v1/FreeFlowingRivers");
var dataRiversStudy = dataRivers.filterMetadata('INC', 'equals', 1).filterBounds(studyArea);

var hist = dataRiversStudy.reduceColumns({
  reducer: ee.Reducer.fixed2DHistogram(0, 100, 10, 0, 100, 10),
  selectors: ['LENGTH_KM', 'DIS_AV_CMS']
}).get('histogram')

print(hist)

https://code.earthengine.google.com/307dd1a69fa244f731700f5b4710126d

0

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.