[Fwd: Re: [mapserver-users] classification of a raster image is changing]

Frank Warmerdam warmerdam at pobox.com
Mon Jun 29 21:06:16 PDT 2009


Stefan,

I notice if I run shp2img with -all_debug set on I see the following:

msDrawGDAL(fahnenankunft): using RAW_WINDOW=17 0 83 100
msDrawGDAL(): red,green,blue,alpha bands = 1,0,0,0
msDrawRasterGDAL_16BitClassification(fahnenankunft):
   scaling to 65536 buckets from range=-0.000183105,24.0002.

I also notice that your classes test for particular ranges of
pixel values:

EXPRESSION ([pixel] > 2 AND [pixel] <= 4)

If you look at the scaling message you see that a range with not quite
integral bounds is being scaled into buckets that will therefor not fall
nicely on integer boundaries.  I inspected your raw data and I see it is
all integer valued.

So I believe the problem is that the odd breakdown of buckets is resulting
in rounding error in the calculations.  For instance, the value 1.0 may fall
into a bucket for the range 0.9994 to 1.0001 which is centered at 0.9998.
The expression is evaluated for the "bucket center", not the real pixel
value, and thus it would not end up in the 1 to 2 class as expected.

So there are a couple fixes.  One is to use PROCESSING directives to set
specific bucket ranges that stay constant and are sure to handle integer
values in a dependable way.  Another way is to use non-integer ranges in
your classes.

My suggestion is to add this to your layer:

   PROCESSING "SCALE=-0.5,24.5"
   PROCESSING "SCALE_BUCKETS=25"

this would produce 25 buckets neatly containing integer values well within
the bucket (not at the edges).

Read the Classifying non-8bit Rasters section of the raster data access
document for more information.

http://www.mapserver.org/input/raster.html#classifying-non-8bit-rasters

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the MapServer-users mailing list