public long[] closestRectangle(BoundingBox rectangleBounds) { return gridSet.closestRectangle(rectangleBounds); }
/** * Find the area that covers the given rectangle with tiles from the subset. * * @param level integer zoom level at which to consider the tiles * @param reqBounds BoundingBox to try to cover. * @return Array of long, the rectangle in tile coordinates, {minx, miny, maxx, maxy} */ public long[] getCoverageIntersection(int level, BoundingBox reqBounds) { long[] reqRectangle = gridSet.closestRectangle(level, reqBounds); GridCoverage gridCoverage = gridCoverageLevels.get(Integer.valueOf(level)); return gridCoverage.getIntersection(reqRectangle); }
@Test public void testClosestRectangle() throws Exception { BoundingBox box = new BoundingBox(-180.0, -90.0, 0.0, 0.0); long[] rectTL = gridSetTL.closestRectangle(box); long[] rectBL = gridSetBL.closestRectangle(box); long[] solution = {0, 0, 1, 0, 1}; assertTrue(Arrays.equals(rectTL, solution)); assertTrue(Arrays.equals(rectBL, solution)); }
public long[] closestRectangle(BoundingBox rectangleBounds) { double rectWidth = rectangleBounds.getWidth(); double rectHeight = rectangleBounds.getHeight(); double bestError = Double.MAX_VALUE; int bestLevel = -1; // Now we loop over the resolutions until for (int i = 0; i < getGridLevels().length; i++) { Grid grid = getGridLevels()[i]; double countX = rectWidth / (grid.getResolution() * getTileWidth()); double countY = rectHeight / (grid.getResolution() * getTileHeight()); double error = Math.abs(countX - Math.round(countX)) + Math.abs(countY - Math.round(countY)); if (error < bestError) { bestError = error; bestLevel = i; } else if (error >= bestError) { break; } } return closestRectangle(bestLevel, rectangleBounds); }
coverage = new long[] {0, 0, maxColX, maxColY, z}; } else { coverage = gridSet.closestRectangle(z, extent);