Skip to content

Commit

Permalink
Adding processing option to classify 16bit rasters using scaled value…
Browse files Browse the repository at this point in the history
…s instead of raw values. (#5834)

Added processing option to classify 16bit rasters based on scaled value - includes a basic test.
  • Loading branch information
sdlime committed Feb 21, 2020
1 parent de351bb commit e83819b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mapdrawgdal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,9 @@ msDrawRasterLayerGDAL_16BitClassification(
int lastC;
struct mstimeval starttime={0}, endtime={0};

const char *pszClassifyScaled;
int bClassifyScaled = FALSE;

if(layer->mask) {
int ret;
layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map,layer->mask));
Expand Down Expand Up @@ -1996,6 +1999,13 @@ msDrawRasterLayerGDAL_16BitClassification(
}
}

/* -------------------------------------------------------------------- */
/* Fetch the scale classification option. */
/* -------------------------------------------------------------------- */
pszClassifyScaled = CSLFetchNameValue( layer->processing, "CLASSIFY_SCALED" );
if( pszClassifyScaled != NULL )
bClassifyScaled = CSLTestBoolean(pszClassifyScaled);

/* -------------------------------------------------------------------- */
/* Fetch the scale processing option. */
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -2104,12 +2114,17 @@ msDrawRasterLayerGDAL_16BitClassification(

cmap[i] = -1;

// i = (int) ((dfOriginalValue - dfScaleMin) * dfScaleRatio+1)-1;
dfOriginalValue = (i+0.5) / dfScaleRatio + dfScaleMin;

/* The creation of buckets takes a significant time when they are many, and many classes
as well. When iterating over buckets, a faster strategy is to reuse first the last used
class index. */
c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float) dfOriginalValue, -1, -1, -1, lastC);
if(bClassifyScaled == TRUE)
c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float) i, -1, -1, -1, lastC);
else
c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float) dfOriginalValue, -1, -1, -1, lastC);

lastC = c;
if( c != -1 ) {
int s;
Expand Down
48 changes: 48 additions & 0 deletions msautotest/gdal/class16_classify_scaled.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Simple test of classification methods on a floating point input.
#
MAP

NAME TEST
STATUS ON
SIZE 400 300
EXTENT 0.5 0.5 399.5 299.5
IMAGECOLOR 255 255 0

IMAGETYPE png8_t

OUTPUTFORMAT
NAME png8_t
DRIVER "GD/PNG"
IMAGEMODE PC256
TRANSPARENT ON
END

LAYER
NAME grid1
TYPE raster
STATUS default
DATA data/float.tif

PROCESSING "SCALE=0,28"
PROCESSING "SCALE_BUCKETS=256"
PROCESSING "CLASSIFY_SCALED=TRUE"

CLASS
NAME "red"
EXPRESSION ([pixel] < 50)
COLOR 255 0 0
END
CLASS
NAME "green"
EXPRESSION ([pixel] >=50 and [pixel] < 150)
COLOR 0 255 0
END
CLASS
NAME "blue"
EXPRESSION ([pixel] > 150)
COLOR 0 0 255
END
END

END # of map file
Binary file added msautotest/gdal/expected/class16_classify_scaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e83819b

Please sign in to comment.