MapServer / MapServer-import

3 stars 2 forks source link

gradient fills on GDAL datasets #1673

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: ross.elliott@infoterra-global.com Date: 2006/02/20 - 13:16

I wanted to assign colour ramps to non-vector datasets (the current gradient
code is vector only). The following patch to mapdrawgdal.c in version 4.8.1 will
allow the GDAL 16 bit classification code to use the same format as the vector
gradients. I've used this on some AAIGRID data with success. As a side note, use
the PROCESSING SCALE, and SCALE_BUCKETS directives to speed up gradient processing.

#### start patch ####
1768a
            /* change colour based on colour range? */
            for(s=0; s<layer->class[c].numstyles; s++)
            {
              if(layer->class[c].styles[s].rangeitem !=  NULL)
                    {
                        msValueToRange(&layer->class[c].styles[s],dfOriginalValue);
                    }
            }
.
1596c
    int  *cmap, c, j, k, bGotNoData = FALSE, bGotFirstValue, s;
.
244c

.
#### end patch ####
tbonfort commented 12 years ago

Author: fwarmerdam Date: 2006/02/22 - 04:59

Ross,

I modified the patch a bit, so the locale now looks like:

                int s;

                /* change colour based on colour range?  Currently we 
                   only address the greyscale case properly. */

                for(s=0; s<layer->class[c].numstyles; s++)
                {
                    if( MS_VALID_COLOR(layer->class[c].styles[s].mincolor)
                        && MS_VALID_COLOR(layer->class[c].styles[s].maxcolor) )
                        msValueToRange(&layer->class[c].styles[s],
                                       sEntry.c1 );
                }

By checking that mincolor and maxcolor are set, I can avoid the need to set 
an unused RANGEITEM in the style.  

I also modified the 'classifed' test to look like this:

  /*
   * Is this image classified?  We consider it classified if there are
   * classes with an expression string *or* a color range.  We don't want
   * to treat the raster as classified if there is just a bogus class here
   * to force inclusion in the legend.
   */
  for( i = 0; i < layer->numclasses; i++ )
  {
      int s;

      /* change colour based on colour range? */
      for(s=0; s<layer->class[i].numstyles; s++)
      {
          if( MS_VALID_COLOR(layer->class[i].styles[s].mincolor)
              && MS_VALID_COLOR(layer->class[i].styles[s].maxcolor) )
          {
              classified = TRUE;
              break;
          }
      }

      if( layer->class[i].expression.string != NULL )
      {
          classified = TRUE;
          break;
      }
  }

Essentially this means you don't have to set a bogus EXPRESSION
on a single class ramped raster in order to get things to go
through the classified case.  

I also incorporated the ramp support into the 8bit classification
case, though it only works sensibly for greyscale rasters as it
assumes the range operation will be done based on the "red" value.

I have added two new tests to the msautotest.

msautotest/gdal/class8_range.map
msautotest/gdal/class16_range.map

The changes have only been incorporated in the 4.9 branch
for now.  The changes are risky enough, and essentially only
adding a new feature, that I hesitate to backport for 4.8.2.
However, if there is sufficient call for it, I could do so.