of course I can. here you are!

this is my code for the resampling method: gc2D is input coverage,
gridcellwidth is the needed cell width and gridcellwidthold is the old one,
which should be changed.

public GridCoverage2D gridResample(GridCoverage2D gc2D, double
gridCellWidth, double gridCellWidthOld) {

                // initialize new processor and parameters
                DefaultProcessor processor = new DefaultProcessor(null);
                ParameterValueGroup parameters =
                       processor.getOperation("Resample").getParameters();
                parameters.parameter("Source").setValue(gc2D);

                // interpolation can be NearestNeighbor, Bilinear or Bicubic
                
parameters.parameter("InterpolationType").setValue("NearestNeighbor");

                // get current grid geometry, envelope and range
                GridGeometry2D curGridGeom = gc2D.getGridGeometry();
                Envelope2D curWorldEnv = curGridGeom.getEnvelope2D();
                GridEnvelope2D curGridEnv = curGridGeom.getGridRange2D();

                // cell size to fixed value
                double cellSize = gridCellWidth;

                int xDim = (int) (curWorldEnv.getWidth()/cellSize);
                int yDim = (int) (curWorldEnv.getHeight()/cellSize);

                GridEnvelope2D newGEnv = new GridEnvelope2D(curGridEnv.x, 
curGridEnv.y,
xDim, yDim);
                GridGeometry2D newGG = new GridGeometry2D(newGEnv, 
(Envelope)curWorldEnv);
                parameters.parameter("GridGeometry").setValue(newGG);

                GridCoverage2D resampledCov = (GridCoverage2D)
processor.doOperation(parameters);
                return resampledCov;
}

this method seems ok.

this is my method for reprojecting the above resampled girdcoverage: input
is resampled gridcoverage

        public GridCoverage2D project(GridCoverage2D gc2D) {

                CoordReferSyst crs = new CoordReferSyst();
                DefaultProcessor processor = new DefaultProcessor(null);

                ParameterValueGroup parameters =
                        processor.getOperation("Resample").getParameters();

                parameters.parameter("Source").setValue(gc2D);

                // interpolation can be NearestNeighbor, Bilinear or Bicubic
                
parameters.parameter("InterpolationType").setValue("NearestNeighbor");

                GridGeometry2D curGridGeom = gc2D.getGridGeometry();
                Envelope curWorldEnv = curGridGeom.getEnvelope2D();

                GridEnvelope2D curGridEnv = curGridGeom.getGridRange2D();

                // create new GridGeometry with half as many cells
                GridGeometry newGridGeom = new GridGeometry2D(curGridEnv, 
curWorldEnv);
                
        
parameters.parameter("CoordinateReferenceSystem").setValue(crs.crs_ETRS89_LAEA());

                parameters.parameter("GridGeometry").setValue(newGridGeom);
                GridCoverage2D reprojectedCov = (GridCoverage2D)
processor.doOperation(parameters);
                
                return reprojectedCov;  
        }

test data: 
http://osgeo-org.1803224.n2.nabble.com/file/n5102432/GRID_TM0_TW_20030105.asc
GRID_TM0_TW_20030105.asc 
to load data in: 
ArcGridReader agr = new ArcGridReader(file);
                        gc2D = (GridCoverage2D) agr.read(null);

the result of reprojecting looks not that bad, but not right yet. I tried
the doOperation method instead of DEFAULT.resample.

it looks like this: 
http://osgeo-org.1803224.n2.nabble.com/file/n5102432/test1.jpg 
the tiny rectangle above europe is the reprojected data. it should be
somewhere in Germany, concret in Dresden.

what am I doing wrong? It is just something with the geometry but I do not
get it right how to fix it.






-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Reprojection-tp5098885p5102432.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------

_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to