Skip to content

Commit d39115a

Browse files
committed
Add quantile discrete for tiffs
1 parent 4876af9 commit d39115a

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

packages/base/src/classificationModes.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ export namespace GeoTiffClassifications {
301301
nClasses: number,
302302
bandNumber: number,
303303
url: string,
304-
sourceId: string
304+
colorRampType: string
305305
) => {
306306
const breaks: number[] = [];
307+
const isDiscrete = colorRampType === 'discrete';
307308

308309
const pool = new Pool();
309310
const tiff = await fromUrl(url);
@@ -323,31 +324,34 @@ export namespace GeoTiffClassifications {
323324
return [];
324325
}
325326

326-
// get the number of values in each bin/
327-
const valuesPerBin = bandSortedValues.length / (nClasses - 1);
328-
329327
// Adapted from https://github.com/GeoTIFF/geoblaze/blob/master/src/histogram/histogram.core.js#L64
330328
// iterate through values and use a counter to
331329
// decide when to set up the next bin.
332-
let numValuesInCurrentBin = 1;
330+
let numValuesInCurrentBin;
331+
let valuesPerBin;
332+
let startIndex;
333333

334-
// Add the first stop
335-
breaks.push(1);
334+
if (isDiscrete) {
335+
valuesPerBin = bandSortedValues.length / nClasses;
336+
numValuesInCurrentBin = 0;
337+
startIndex = 0;
338+
} else {
339+
valuesPerBin = bandSortedValues.length / (nClasses - 1);
340+
breaks.push(1);
341+
numValuesInCurrentBin = 1;
342+
startIndex = 1;
343+
}
336344

337-
for (let i = 1; i < bandSortedValues.length; i++) {
345+
for (let i = startIndex; i < bandSortedValues.length; i++) {
338346
if (numValuesInCurrentBin + 1 < valuesPerBin) {
339-
numValuesInCurrentBin += 1;
347+
numValuesInCurrentBin++;
340348
} else {
341-
// if it is the last value, add it to the bin and start setting up for the next one
342-
const binMax = bandSortedValues[i] as number;
349+
breaks.push(bandSortedValues[i] as number);
343350
numValuesInCurrentBin = 0;
344-
breaks.push(binMax);
345351
}
346352
}
347353

348-
// add the last stop
349-
const binMax = 65535;
350-
breaks.push(binMax);
354+
breaks.push(65535);
351355

352356
return breaks;
353357
};

packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ const SingleBandPseudoColor = ({
358358

359359
const currentBand = bandRows[selectedBand - 1];
360360
const source = context.model.getSource(layer?.parameters?.source);
361-
const sourceId = layer.parameters?.source;
362361
const sourceInfo = source?.parameters?.urls[0];
363362
const nClasses = selectedMode === 'continuous' ? 52 : +numberOfShades;
364363
const colorMap = colormap({
@@ -380,7 +379,7 @@ const SingleBandPseudoColor = ({
380379
nClasses,
381380
selectedBand,
382381
sourceInfo.url,
383-
sourceId
382+
selectedFunction
384383
);
385384
break;
386385
case 'continuous':

0 commit comments

Comments
 (0)