Thanks Martin and Michael, now I got it.

Here's some code for the archive (hints for optimization welcome):

// Some preparations
GridCoverage2D gridCoverage = ...;
RenderedImage renderedImage = gridCoverage.getRenderedImage();
Raster renderedGrid = renderedImage.getData();
int imgMinX = renderedImage.getMinX();
int imgMinY = renderedImage.getMinY();
int imgWidth = renderedImage.getWidth();
int imgHeight = renderedImage.getHeight();
Feature [] ROIs = ...
Geometry currROI = null;
MathTransform mt = gridCoverage.getGridGeometry().getGridToCRS();
Geometry pnt = null;
Geometry pntTrans = null;
RandomIter sourceIterator = RandomIterFactory.create( renderedGrid, null );

// Iterize over ROIs            
for ( int ROI=0; ROI<ROIs.length; ROI++ ) {
                                
        // Example: count pixels and calculate sum of values in ROIs
        int numPixels = 0;
        int band = 0;
                        
        for( int h=imgMinY; h<imgMinY+imgHeight; h++ ) {
                for( int w=imgMinX; w<imgMinX+imgWidth; w++ ) {

                        // Transform pixel coordinates into geographic 
coordinates
                        pnt = new GeometryFactory().createPoint( new 
Coordinate( (double) w,
(double) h ) );
                                        
                        try {
                                pntTrans = 
org.geotools.geometry.jts.JTS.transform(pnt, mt);
                        } catch ( Exception e ) {
                                ...
                        }
                                        
                        // Check whether ROI contains pixel and do calculation
                        if ( currROI.contains( pntTrans ) ) {
                                numPixels++;
                                sum += sourceIterator.getSampleFloat( w, h, 
band );
                        }
                }
        }

        System.out.println("Number of pixels in ROI " + (ROI+1) + ": " +
numPixels);
        System.out.println("Sum of pixel values in ROI " + (ROI+1) + ": " + 
sum);
}

-- 
View this message in context: 
http://www.nabble.com/Get-world-coordinates-of-a-grid-coverage-tp17879556p18109828.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to