Sorry - wrong mail address. Again....

Hello again,

another question I have is how to work with GridCoverage2D objects.  
To do any operation with the grid values I tried to store them in an  
array:

GridCoverage2D gridCoverage = (GridCoverage2D) grid; // grid is an  
Object

/*System.out.println("### GridCoverage2D Info ###");
  System.out.println("# Min: " + gridCoverage.getSampleDimension 
(0).getMinimumValue());
System.out.println("# Max: " + gridCoverage.getSampleDimension 
(0).getMaximumValue());
System.out.println("# NoData: " + gridCoverage.getSampleDimension 
(0).getNoDataValues());
gridCoverage.show("TestTIFF");*/

RenderedImage renderedImage = gridCoverage.getRenderedImage();
Raster renderedGrid = renderedImage.getData();

/*System.out.println("### Raster Info ###");
System.out.println("# Height: " + renderedGrid.getHeight());
System.out.println("# Width: " + renderedGrid.getWidth());
System.out.println("# NumberOfBands: " + renderedGrid.getNumBands());*/

// Get data values of the grid
int gridMinX = renderedGrid.getMinX();
int gridMinY = renderedGrid.getMinY();
int gridWidth = renderedGrid.getWidth();
int gridHeight = renderedGrid.getHeight();
double[] dataBlock = null;
dataBlock = renderedGrid.getPixels(gridMinX, gridMinY, gridWidth,  
gridHeight, dataBlock);
double[][] gridValues = new double[gridHeight][gridWidth];
int base;

for (int i=0; i<gridHeight; i++) {
    base = i * gridWidth;
    //System.arraycopy(dataBlock, base, gridValues[i], 0, gridWidth);
}

int numRows = gridValues.length;
int numCols = gridValues[0].length;

/*System.out.println("### Values Info ###");
System.out.println("# NumCols: " + numCols);
System.out.println("# NumRows: " + numRows);
System.out.println("# Samples:");
        for (int i=0; i<5; i++) {
            System.out.println("Line " + (i+1));
            for (int j=0; j<10; j++) {
                System.out.println(" Row " + (j+1) + " = " +  
gridValues[i][j]);
            }
        }*/

Unfortunately I get an OutOfMemory: Java Heap Space exception,  
althought my test grid is not really a large one (somewhat 2800 x  
2500 pixels). If I give Java more memory, the error does not disappear.

Now my question: Is there I better solution to access and work with  
the grid values - maybe directly from the GridCoverage2D - to avoid  
the data transfer to an array? Or what else can I do?


Thanks,

Christian


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to