for (int i = grid.getXmin(); i < grid.getXmax(); i++) {
for (int j = grid.getYmin(); j < grid.getYmax(); j++) {
double x = grid.getLowerLeft().x + (i - grid.getXmin()) * grid.getTileWidth();
double y = grid.getLowerLeft().y + (j - grid.getYmin()) * grid.getTileHeight();
// layer coordinates
Bbox worldBox;
Bbox layerBox;
if (needTransform) {
layerBox = new Bbox(x, y, grid.getTileWidth(), grid.getTileHeight());
// Transforming back to map coordinates will only result in a proper grid if the transformation
// is nearly affine
worldBox = geoService.transform(layerBox, layerToMap);
} else {
worldBox = new Bbox(x, y, grid.getTileWidth(), grid.getTileHeight());
layerBox = worldBox;
}
// Rounding to avoid white space between raster tiles lower-left becomes upper-left in inverted y-space
Bbox screenBox = new Bbox(Math.round(scale * worldBox.getX()), -Math.round(scale * worldBox.getMaxY()),
Math.round(scale * worldBox.getMaxX()) - Math.round(scale * worldBox.getX()), Math.round(scale
* worldBox.getMaxY())
- Math.round(scale * worldBox.getY()));
RasterTile image = new RasterTile(screenBox, getId() + "." + bestResolution.getLevel() + "." + i