Hello
I get an error when reprojecting an image : the values of the pixels in the
result image are one unit lesser than the corresponding pixels in the
original image.
Have I made a mistake somewhere in the provided code ? Is it a bug due to
GeoTools or to JAI or... ?
Below is the code I have used, you will find the image file in attachment.
Thanks for your help.
Fred






import java.awt.Point;
import java.awt.geom.Point2D;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.Interpolation;
import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.coverage.processing.Operations;
import org.geotools.geometry.Envelope2D;
import org.geotools.referencing.CRS;
import org.opengis.geometry.Envelope;



/**
 * Reprojects a PGM file.
 * The values of all the result file's pixels all are one unit lesser than
the original file's corresponding pixel.
 *
 * Usage : java ReprojectionProblem
 */
public class ReprojectionProblem {
    public static void main (String[] args) {

        try {

            // loading the input file
            RenderedOp rop = JAI.create("fileload", "in.pgm");

            // getting a gridcoverage whithin the input file
            GridCoverageFactory fac = new GridCoverageFactory();
            GridCoverage2D  gc = fac.create("NO
NAME",rop.getAsBufferedImage() , new
Envelope2D(CRS.decode("EPSG:4326"),-20,-20,40,40));

            // displaying the value at coordinates point (0,0) BEFORE
reprojection
            int[] array = new int[1];
            Point2D pt = new Point(0,0);
            gc.evaluate(pt, array);
            System.out.println("BEFORE: " + array[0]);

            // getting the target Envelope
            Envelope env = new
Envelope2D(CRS.decode("EPSG:4326"),-40,-40,80,80);

            // reprojecting
            GridCoverage2D gc2 =
(GridCoverage2D)Operations.DEFAULT.resample(gc,env,Interpolation.getInstance(Interpolation.INTERP_BILINEAR));

            // displaying the value at coordinates point (0,0) AFTER
reprojection
            array = new int[1];
            pt = new Point(0,0);
            gc2.evaluate(pt, array);
            System.out.println("AFTER: " + array[0]);

            // getting the result image
            RenderedImage res = gc2.getRenderedImage();

            // saving the result image
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(res);
            pb.add("out.pgm");
            pb.add("pnm");
            JAI.create("filestore", pb);


        } catch (Exception e) {
            e.printStackTrace();
        }




    }
}

<<attachment: in.pgm>>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to