private static double[] resolutions(Grid[] grids) { double[] resolutions = new double[grids.length]; for (int i = 0; i < resolutions.length; i++) { resolutions[i] = grids[i].getResolution(); } return resolutions; }
public double[] getResolutions() { double[] ret = new double[gridCoverageLevels.size()]; final int zoomStart = getZoomStart(); final int zoomStop = getZoomStop(); final Grid[] gridLevels = gridSet.getGridLevels(); for (int z = zoomStart, i = 0; z <= zoomStop; z++, i++) { Grid grid = gridLevels[z]; ret[i] = grid.getResolution(); } return ret; }
protected long[] closestIndex(BoundingBox tileBounds) throws GridMismatchException { double wRes = tileBounds.getWidth() / getTileWidth(); double bestError = Double.MAX_VALUE; int bestLevel = -1; double bestResolution = -1.0; for (int i = 0; i < getGridLevels().length; i++) { Grid grid = getGridLevels()[i]; double error = Math.abs(wRes - grid.getResolution()); if (error < bestError) { bestError = error; bestResolution = grid.getResolution(); bestLevel = i; } else { break; } } if (Math.abs(wRes - bestResolution) > (0.1 * wRes)) { throw new ResolutionMismatchException(wRes, bestResolution); } return closestIndex(bestLevel, tileBounds); }
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); }
protected long[] closestIndex(int level, BoundingBox tileBounds) throws GridAlignmentMismatchException { Grid grid = getGridLevels()[level]; double width = grid.getResolution() * getTileWidth(); double height = grid.getResolution() * getTileHeight(); double x = (tileBounds.getMinX() - tileOrigin()[0]) / width; double y = (tileBounds.getMinY() - tileOrigin()[1]) / height; long posX = (long) Math.round(x); long posY = (long) Math.round(y); if (Math.abs(x - posX) > 0.1 || Math.abs(y - posY) > 0.1) { throw new GridAlignmentMismatchException(x, posX, y, posY); } if (yBaseToggle) { posY = posY + grid.getNumTilesHigh(); } long[] ret = {posX, posY, level}; return ret; }
public BoundingBox boundsFromIndex(long[] tileIndex) { final int tileZ = (int) tileIndex[2]; Grid grid = getGrid(tileZ); final long tileX = tileIndex[0]; final long tileY; if (yBaseToggle) { tileY = tileIndex[1] - grid.getNumTilesHigh(); } else { tileY = tileIndex[1]; } double width = grid.getResolution() * getTileWidth(); double height = grid.getResolution() * getTileHeight(); final double[] tileOrigin = tileOrigin(); BoundingBox tileBounds = new BoundingBox( tileOrigin[0] + width * tileX, tileOrigin[1] + height * (tileY), tileOrigin[0] + width * (tileX + 1), tileOrigin[1] + height * (tileY + 1)); return tileBounds; }
gridSet.getGridLevels()[idx].getResolution() / 2 - gridSet.getGridLevels()[idx + 1].getResolution(); > gridSet.getGridLevels()[idx + 1].getResolution() * 0.025) { throw new GeoWebCacheException( "The resolution is not decreasing by a factor of two for "
/** * Finds the spatial bounding box of a rectangular group of tiles. * * @param rectangleExtent the rectangle of tiles. {minx, miny, maxx, maxy} in tile coordinates * @return the spatial bounding box in the coordinates of the SRS used by the GridSet */ protected BoundingBox boundsFromRectangle(long[] rectangleExtent) { Grid grid = getGridLevels()[(int) rectangleExtent[4]]; double width = grid.getResolution() * getTileWidth(); double height = grid.getResolution() * getTileHeight(); long bottomY = rectangleExtent[1]; long topY = rectangleExtent[3]; if (yBaseToggle) { bottomY = bottomY - grid.getNumTilesHigh(); topY = topY - grid.getNumTilesHigh(); } double[] tileOrigin = tileOrigin(); double minx = tileOrigin[0] + width * rectangleExtent[0]; double miny = tileOrigin[1] + height * (bottomY); double maxx = tileOrigin[0] + width * (rectangleExtent[2] + 1); double maxy = tileOrigin[1] + height * (topY + 1); BoundingBox rectangleBounds = new BoundingBox(minx, miny, maxx, maxy); return rectangleBounds; }
/** * Find the rectangle of tiles that most closely covers the given rectangle * * @param level integer zoom level to consider tiles at * @param rectangeBounds rectangle to match * @return Array of long, the rectangle of tiles in tile coordinates: {minx, miny, maxx, maxy, * level} */ protected long[] closestRectangle(int level, BoundingBox rectangeBounds) { Grid grid = getGridLevels()[level]; double width = grid.getResolution() * getTileWidth(); double height = grid.getResolution() * getTileHeight(); long minX = (long) Math.floor((rectangeBounds.getMinX() - tileOrigin()[0]) / width); long minY = (long) Math.floor((rectangeBounds.getMinY() - tileOrigin()[1]) / height); long maxX = (long) Math.ceil(((rectangeBounds.getMaxX() - tileOrigin()[0]) / width)); long maxY = (long) Math.ceil(((rectangeBounds.getMaxY() - tileOrigin()[1]) / height)); if (yBaseToggle) { minY = minY + grid.getNumTilesHigh(); maxY = maxY + grid.getNumTilesHigh(); } // We substract one, since that's the tile at that position long[] ret = {minX, minY, maxX - 1, maxY - 1, level}; return ret; }
double dGridExtent = grid.getNumTilesHigh(); double top = tileOrigin()[1] + dTileHeight * grid.getResolution() * dGridExtent;
double width = grid.getResolution() * gridSubset.getTileWidth(); double height = grid.getResolution() * gridSubset.getTileHeight();
public void testBoundingBoxEPSG3785() throws Exception { BoundingBox extent = new BoundingBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34); GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG3857(), extent, false, 6, null, 0.00028, 256, 256, false); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals((20037508.34 * 2) / 256, grid0.getResolution()); assertEquals(1L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[3]; assertEquals((long) Math.pow(2, 3), grid3.getNumTilesWide()); assertEquals((long) Math.pow(2, 3), grid3.getNumTilesHigh()); }
public void testResolutionsArrayEPSG3785() throws Exception { BoundingBox extent = new BoundingBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34); double[] resolutions = { (20037508.34 * 2) / 256, (20037508.34 * 2) / 512, (20037508.34 * 2) / 1024, (20037508.34 * 2) / 2048 }; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG3857(), extent, false, resolutions, null, null, 0.00028, null, 256, 256, false); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals((20037508.34 * 2) / 256, grid0.getResolution()); assertEquals(1L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[3]; assertEquals((long) Math.pow(2, 3), grid3.getNumTilesWide()); assertEquals((long) Math.pow(2, 3), grid3.getNumTilesHigh()); }
public void testBoundingBoxEPSG4326() throws Exception { BoundingBox extent = new BoundingBox(-180, -90, 180, 90); GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, 4, null, 0.00028, 256, 256, false); assertEquals("test", gridSet.getName()); assertEquals(-180.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(4, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 256, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[3]; assertEquals(180.0 / 2048, grid3.getResolution()); assertEquals((long) Math.pow(2, 4), grid3.getNumTilesWide()); assertEquals((long) Math.pow(2, 3), grid3.getNumTilesHigh()); }
public void testResolutionsArrayEPSG4326() throws Exception { BoundingBox extent = new BoundingBox(-180, -90, 180, 90); double[] resolutions = {180.0 / 256, 180.0 / 512, 180.0 / 1024, 180.0 / 2048}; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, resolutions, null, null, 0.00028, null, 256, 256, false); assertEquals("test", gridSet.getName()); assertEquals(-180.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(resolutions.length, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 256, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[3]; assertEquals(180.0 / 2048, grid3.getResolution()); assertEquals((long) Math.pow(2, 4), grid3.getNumTilesWide()); assertEquals((long) Math.pow(2, 3), grid3.getNumTilesHigh()); }
public void testResolutionsArrayTricky1() throws Exception { // This should be expanded in the X direction BoundingBox extent = new BoundingBox(-173, -90, 180, 96); double[] resolutions = {180.0 / 200, 180.0 / 400, 180.0 / 800}; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, resolutions, null, null, 0.00028, null, 200, 200, false); assertEquals(-173.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(resolutions.length, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 200, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(2L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[2]; assertEquals(180.0 / 800, grid3.getResolution()); assertEquals(8L, grid3.getNumTilesWide()); assertEquals(5L, grid3.getNumTilesHigh()); }
public void testBoundingBoxTricky2() throws Exception { BoundingBox extent = new BoundingBox(-180, -90, 180, 82); SRS srs = SRS.getEPSG4326(); GridSet gridSet = GridSetFactory.createGridSet( "test", srs, extent, false, 4, null, 0.00028, 256, 256, false); assertEquals("test", gridSet.getName()); assertEquals(-180.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(4, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 256, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); }
public void testBoundingBoxTricky1() throws Exception { BoundingBox extent = new BoundingBox(-180, -90, 172, 90); GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, 4, null, 0.00028, 256, 256, false); assertEquals("test", gridSet.getName()); assertEquals(-180.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(4, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 256, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(1L, grid0.getNumTilesHigh()); }
assertEquals(500D / tileHeight / tilesHigh, grid0.getResolution());
assertEquals(50D / 20D, grid0.getResolution());