Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find NDVI and other vegetation indices and then find changes in time with tif images.

I've been using Geotools for this. I took 2 tiff images, then using QGIS I changed them to PNG because original ones are huge. Then taking those 2 PNGs I created NDVI image using JAI.

The problem is that I couldn't show this file with Geotools. You can look at the code here:

private void constructNDVI(File band3File, File band4File)
        throws IOException {
    PlanarImage iNIR = JAI.create("fileload", band3File.getAbsolutePath());
    PlanarImage iVIS = JAI.create("fileload", band4File.getAbsolutePath());
    // The pixels on those images must be processed as floating-point
    // values!
    ParameterBlock pbConvert = new ParameterBlock();
    PlanarImage NIR = JAI.create("format", pbConvert);
    pbConvert = new ParameterBlock();
    PlanarImage VIS = JAI.create("format", pbConvert);
    // Calculate the denominator (NIR-VIS).
    ParameterBlock pbd = new ParameterBlock();
    PlanarImage denominator = JAI.create("subtract", pbd);
    // Calculate the numerator (NIR+VIS).
    ParameterBlock pbn = new ParameterBlock();
    PlanarImage numerator = JAI.create("add", pbd);
    // Calculate the NDVI.
    ParameterBlock pbNDVI = new ParameterBlock();
    PlanarImage ndvi = JAI.create("divide", pbNDVI);
    DisplayNBImage disp = new DisplayNBImage(ndvi);
    String filename = new Date().getTime() + ".png";
    JAI.create("filestore", disp.getSurrogateImage(), filename, "PNG");
    File file = new File(filename);

You can find DisplayNBImage here.

private void showNDVI(File file) throws IOException {
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    AbstractGridCoverage2DReader reader = format.getReader(file);
    final MapContent map = new MapContent();
    JMapFrame frame = new JMapFrame(map);

I can open the file I've created in constructNDVI method in Windows Photo Viewer or QGis. But 2nd line in showNDVI gives

Exception in thread "main" java.lang.UnsupportedOperationException: Trying to get a reader from an unknown format.

I've tried bmp, tiff but no luck. How can I overcome this?

In fact, proposing non-Jai way of the same thing would be awesome.

share|improve this question
does the file you are trying to read have a world file? – iant Dec 30 '12 at 8:18
No, it is only a PNG file. I've tried same thing with GeoTiff and BMP but in both JAI didn't create a world file. – GokcenG Dec 30 '12 at 9:54
GeoTools is expecting a georeferenced file. – iant Dec 30 '12 at 9:59
First 2 files are georeferenced, it seems JAI is removing this data. How can I manage conserve this data while creating this NDVI map? As I said if there is another way of this(without JAI), it will be good to hear. – GokcenG Dec 30 '12 at 16:57

Your Answer


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

Browse other questions tagged or ask your own question.