@@ -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 } ;
0 commit comments