Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm serving a NDVI coverage via Mapserver. So, one band, float32 values, [-1.0, 1.0]. I want to display the NDVI in greyscale, and generate a legend. I've tried 2 things:

  • Create two dummy classes, just for testing:

Dummy classes

So, my legend looks like this

Legend

And the image, obviously, is red and blue: http://dl.dropbox.com/u/6599273/capturas/ndvi_en_gvsig.png

But I'd like to see the image in greyscale... The I've tried the next thing

The problem is now I can't see any legend, because I've not created any class. I'd like to see all the colors of the grayscale image in my legend.

How could I do it?

Many thanks in advance

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Honestly, a red and blue scaled NDVI map is not particularly representative. Check this example for a well colored NDVI and EVI map: http://www.grassbook.org/neteler/rs/modis_ndvi_evi/modis_NDVI_EVI_calabria_comparison.png

The colors are predefined in GRASS GIS, see http://grass.osgeo.org/gdp/html_grass64/r.colors.html (you could extract easily the color ramp from the source code, ping me if you need help).

share|improve this answer
    
No, I don't want red and blue colors. I was just testing how the legend is generated based on the CLASS elements of the mapfile. My problem is I can see the image in grey levels by using the PROCESSING "SCALE=-1.0, 1.0" option and no CLASS elements. But in that case, I can't get a legend graphic, because it's constructed based on the CLASS elements (I guess)... –  jorgeas80 Sep 28 '11 at 9:16
    
BTW, thanks for the GRASS ref. I was able to generate a legend with GRASS, by applying the grey color to the band and using d.legend -s map=mymap@mymapset. So, GRASS can generate a legend based only in the raster file, and Mapserver needs a mapfile with CLASS elements (am I right?). Now, I could create a HTML legend, using the output image from GRASS, I guess... –  jorgeas80 Sep 28 '11 at 11:16
    
Yes, GRASS only needs the raster map. Your approach may work. –  markusN Sep 29 '11 at 13:54
add comment

I'm a little confused whether your wish for grayscale output is for display purposes, or for output format type (8-bit output). In any case, if the desire is solely for display, then obviously you could create a simple 2-Color B&W image by using the RGB values for Black and White in your 2-color example above:

CLASS
  NAME "black"
  EXPRESSION ([pixel] < 2000)
  STYLE
    COLOR 0 0 0
  END
END

CLASS
  NAME "white"
  EXPRESSION ([pixel] >= 2000)
  STYLE
    COLOR 255 255 255
  END
END

If on the other hand you want more that 2 colors in your grayscale output, you can simply eliminate the CLASS block entirely. With a single band image, MapServer will automatically render a grayscale image that is scaled from 0 - 255 using the range of values in the data.

Finally, if you want to control the ranges over which the scaling occurs, you can do the following:

CLASS
NAME "Grayscale"
EXPRESSION ([pixel] >= 0 and [pixel] < 5000)
STYLE
  COLORRANGE 0 0 0   255 255 255
  DATARANGE 0   5000
END

END

This can also be made more elaborate with multiple scales:

    CLASS
      NAME "low scale"
      EXPRESSION ([pixel] >= 0 and [pixel] < 500)
      STYLE
        COLORRANGE 0 0 0   100 100 100
        DATARANGE 0   2000
      END
    END

  CLASS
    NAME "high scale"
    EXPRESSION ([pixel] >= 500 and [pixel] < 5000)
    STYLE
      COLORRANGE 100 100 100   255 255 255
      DATARANGE 500  5000
    END
  END

As far as legends go, to my knowledge there is no way in MapServer to create an image that shows the linearly interpolation gradient from one color to another.

Matplotlib, or Protoviz, or Imagemagick might be of use to you in constructing a legend image.

share|improve this answer
    
Yes, I only have display purposes. About eliminating the CLASS elements, that is one the tests I did (the second one). But as I said, then I don't have a generated legend. I could generate a legend that shows the gradient by using GRASS, and I'm working with this now. But I didn't test the COLORRANGE/DATARANGE commands. This could be another way. Thanks! –  jorgeas80 Oct 26 '11 at 15:03
add comment

I would test that instruction (not tested) :

PROCESSING "BANDS=grey"

See the following documentation section.

share|improve this answer
    
Many thanks. I've tested it, but I actually get the only raster band without that option. –  jorgeas80 Sep 28 '11 at 9:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.