MosaicGrid { public Rectangle computeBounds(Geometry roiGeometry) { Rectangle region = new Rectangle(gridWidth, gridHeight); if (roiGeometry != null) { final Coordinate[] coordinates = roiGeometry.getBoundary().getCoordinates(); double gxmin = Double.POSITIVE_INFINITY; double gxmax = Double.NEGATIVE_INFINITY; double gymin = Double.POSITIVE_INFINITY; double gymax = Double.NEGATIVE_INFINITY; for (Coordinate coordinate : coordinates) { gxmin = Math.min(gxmin, coordinate.x); gxmax = Math.max(gxmax, coordinate.x); gymin = Math.min(gymin, coordinate.y); gymax = Math.max(gymax, coordinate.y); } gxmin -= pixelSize / 2; gxmax += pixelSize / 2; gymin -= pixelSize / 2; gymax += pixelSize / 2; if (gxmin < -180.0 || gxmax > 180.0) { gxmin = -180.0; gxmax = 180.0; } if (gymin < -90.0) { gymin = -90.0; } if (gymax > 90.0) { gymax = 90.0; } final int x = (int) Math.floor((180.0 + gxmin) / pixelSize); final int y = (int) Math.floor((90.0 - gymax) / pixelSize); final int width = (int) Math.ceil((gxmax - gxmin) / pixelSize + 1); final int height = (int) Math.ceil((gymax - gymin) / pixelSize + 1); final Rectangle unclippedOutputRegion = new Rectangle(x, y, width, height); region = unclippedOutputRegion.intersection(region); } LOG.info("source product bounds: " + region); return region; } MosaicGrid();   MosaicGrid(int macroTileSize, int numTileY, int tileSize, boolean withIntersectionCheck, int maxReducers, int maxMacroTileCountX, String regionWkt); static MosaicGrid create(Configuration conf); void saveToConfiguration(Configuration conf); int getMacroTileSize(); int getTileSize(); double getPixelSize(); int getNumTileX(); int getNumTileY(); int getNumMacroTileX(); int getNumMacroTileY(); Rectangle computeBounds(Geometry roiGeometry); Rectangle alignToTileGrid(Rectangle rectangle); Geometry computeProductGeometry(Product product); TileIndexWritable[] getTileIndices(List<Point> tilePointIndices); Rectangle getTileRectangle(int tileX, int tileY); Rectangle getMacroTileRectangle(int tileX, int tileY); CrsGeoCoding createMacroCRS(Point macroTile); int getPartition(int macroTileX, int macroTileY); int getNumReducers();  }
@Test public void testComputeBounds() throws Exception { MosaicGrid mosaicGrid = new MosaicGrid(); Rectangle rectangle = mosaicGrid.computeBounds(null); assertNotNull(rectangle); assertEquals(0, rectangle.x); assertEquals(0, rectangle.y); assertEquals(370 * 360, rectangle.width); assertEquals(370 * 180, rectangle.height); Geometry geometry = GeometryUtils.createGeometry("polygon((-180 90, -180 80, -170 80, -170 90, -180 90))"); rectangle = mosaicGrid.computeBounds(geometry); assertNotNull(rectangle); assertEquals(0, rectangle.x); assertEquals(0, rectangle.y); assertEquals(370 * 10 * 36, rectangle.width); assertEquals(370 * 10 + 2, rectangle.height); geometry = GeometryUtils.createGeometry("polygon((-179.5 89.5, -179.5 80.5, -170.5 80.5, -170.5 89.5, -179.5 89.5))"); rectangle = mosaicGrid.computeBounds(geometry); assertNotNull(rectangle); assertEquals(185 - 1, rectangle.x); assertEquals(185 - 1, rectangle.y); assertEquals(370 * 9 + 3, rectangle.width); assertEquals(370 * 9 + 2, rectangle.height); }