for( Object layer : layers ) {
if (layer instanceof IGeoResource) {
IGeoResource geoResource = (IGeoResource) layer;
try {
GridGeometry2D gridGeometry = null;
if (geoResource.canResolve(GridGeometry2D.class)) {
gridGeometry = geoResource.resolve(GridGeometry2D.class, new NullProgressMonitor());
} else if (geoResource.canResolve(GridCoverage.class)) {
GridCoverage2D gridCoverage = (GridCoverage2D) geoResource.resolve(GridCoverage.class,
new NullProgressMonitor());
gridGeometry = gridCoverage.getGridGeometry();