/** * Helper function for calculating width and height * * @param grid * @param z * @return * @throws GeoWebCacheException */ protected int[] calculateWidthHeight(GridSubset grid, int z) throws GeoWebCacheException { long[] bounds = grid.getCoverage(z); int[] widthHeight = new int[2]; widthHeight[0] = (int) (bounds[2] - bounds[0] + 1); widthHeight[1] = (int) (bounds[3] - bounds[1] + 1); return widthHeight; }
/** * Indicates whether this gridsubset coverage contains the given tile * * @param index the tile index to check for coverage inclusion * @return {@code true} if {@code index} is inside this grid subset's coverage, {@code false} * otherwise */ public boolean covers(long[] index) { final int level = (int) index[2]; final long[] coverage = getCoverage(level); if (coverage == null) { return false; } if (index[0] >= coverage[0] && index[0] <= coverage[2] && index[1] >= coverage[1] && index[1] <= coverage[3]) { return true; } return false; }
public BoundingBox getCoverageBounds(int level) { long[] coverage = getCoverage(level); return gridSet.boundsFromRectangle(coverage); }
public long[] getCoverageBestFit() { int level; long[] cov = null; final int zoomStart = getZoomStart(); final int zoomStop = getZoomStop(); for (level = zoomStop; level > zoomStart; level--) { cov = getCoverage(level); if (cov[0] == cov[2] && cov[1] == cov[3]) { break; } } cov = getCoverage(level); return cov; }
public long[][] getCoverages() { long[][] ret = new long[gridCoverageLevels.size()][5]; final int zoomStart = getZoomStart(); final int zoomStop = getZoomStop(); for (int level = zoomStart, i = 0; level <= zoomStop; level++, i++) { long[] cov = getCoverage(level); ret[i] = cov; } return ret; }
/** * Performs a lookup against an internal raster. * * @param grid * @param idx * @return */ private boolean lookup(GridSubset grid, long[] idx) { BufferedImage mat = matrices.get(grid.getName())[(int) idx[2]]; long[] gridCoverage = grid.getCoverage((int) idx[2]); // Changing index to top left hand origin long x = idx[0] - gridCoverage[0]; long y = gridCoverage[3] - idx[1]; return (mat.getRaster().getSample((int) x, (int) y, 0) == 0); }
for (int i = zoomStart; i <= zoomStop; i++) { Grid grid = gridSet.getGrid(i); long[] coverage = getCoverage(i);
public void test5gridLevels4326() throws Exception { BoundingBox bbox = new BoundingBox(-124.731422, 24.955967, -66.969849, 49.371735); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 10); long[][] solution = {{0, 0, 0, 0, 0}, {0, 1, 1, 1, 1}, {1, 2, 2, 3, 2}, {2, 5, 5, 6, 3}}; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void test1gridLevels4326() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 180.0, 90.0); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 10); long[][] solution = {{1, 0, 1, 0, 0}, {2, 1, 3, 1, 1}, {4, 2, 7, 3, 2}, {8, 4, 15, 7, 3}}; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println( i + " " + Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void test1gridLevels900913() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 20037508.34, 20037508.34); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg3857(), bbox, 0, 10); long[][] solution = { {0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}, {2, 2, 3, 3, 2}, {4, 4, 7, 7, 3}, {8, 8, 15, 15, 4} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println("test1gridLevels900913, level " + i); System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void apply(ConveyorTile convTile) throws RequestFilterException { TileLayer tl = convTile.getLayer(); // SRS srs = convTile.getSRS(); GridSubset gridSubset = tl.getGridSubset(convTile.getGridSetId()); int z = (int) convTile.getTileIndex()[2]; long[] gridCoverage = gridSubset.getCoverage(z); // Figure out the radius long width = gridCoverage[2] - gridCoverage[0]; long height = gridCoverage[3] - gridCoverage[1]; // Rounding must always err on the side of // caution if you want to use KML hierarchies long maxRad = 0; if (width > height) { maxRad = (width / 4) + 1; } else { maxRad = (height / 4) + 1; } // Figure out how the requested bounds relate long midX = gridCoverage[0] + width / 2; long midY = gridCoverage[1] + height / 2; long xDist = midX - convTile.getTileIndex()[0]; long yDist = midY - convTile.getTileIndex()[1]; long rad = Math.round(Math.sqrt(xDist * xDist + yDist * yDist)); if (rad > maxRad) { throw new BlankTileException(this); } }
public void test2gridLevels900913() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 20037508.34, 20037508.34); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg3857(), bbox, 0, 10); long[][] solution = { {0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}, {2, 2, 3, 3, 2}, {4, 4, 7, 7, 3}, {8, 8, 15, 15, 4}, {16, 16, 31, 31, 5}, {32, 32, 63, 63, 6} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println("test2gridLevels900913, level " + i); System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void test3gridLevels900913() throws Exception { BoundingBox bbox = new BoundingBox(-500000, -500000, 500000, 500000); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg3857(), bbox, 0, 10); long[][] solution = { {0, 0, 0, 0, 0}, {0, 0, 1, 1, 1}, {1, 1, 2, 2, 2}, {3, 3, 4, 4, 3}, {7, 7, 8, 8, 4}, {15, 15, 16, 16, 5}, {31, 31, 32, 32, 6}, {62, 62, 65, 65, 7} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println("test3gridLevels900913, level " + i); System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void test2gridLevels4326() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 180, 90); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 10); long[][] solution = { {1, 0, 1, 0, 0}, {2, 1, 3, 1, 1}, {4, 2, 7, 3, 2}, {8, 4, 15, 7, 3}, {16, 8, 31, 15, 4}, {32, 16, 63, 31, 5}, {64, 32, 127, 63, 6} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
private String buildGetMap(final boolean directWMSIntegrationEndpoint, final String queryLayerName, final String gridsetId, String styles, final TileLayer tileLayer) { final GridSubset gridSubset = tileLayer.getGridSubset(gridsetId); long[] coverage = gridSubset.getCoverage(0); long[] tileIndex = { coverage[0], coverage[1], coverage[4] }; BoundingBox bounds = gridSubset.boundsFromIndex(tileIndex); final String endpoint = directWMSIntegrationEndpoint ? "wms" : "gwc/service/wms"; StringBuilder sb = new StringBuilder(endpoint); sb.append("?service=WMS&request=GetMap&version=1.1.1&format=image/png"); sb.append("&layers=").append(queryLayerName); sb.append("&srs=").append(gridSubset.getSRS()); sb.append("&width=").append(gridSubset.getGridSet().getTileWidth()); sb.append("&height=").append(gridSubset.getGridSet().getTileHeight()); sb.append("&styles="); if (styles != null) { sb.append(styles); } sb.append("&bbox=").append(bounds.toString()); return sb.toString(); }
public void test3gridLevels4326() throws Exception { BoundingBox bbox = new BoundingBox(-10.0, -10.0, 10.0, 10.0); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 10); long[][] solution = { {0, 0, 1, 0, 0}, {1, 0, 2, 1, 1}, {3, 1, 4, 2, 2}, {7, 3, 8, 4, 3}, {15, 7, 16, 8, 4}, {30, 14, 33, 17, 5}, {60, 28, 67, 35, 6}, {120, 56, 135, 71, 7} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void test4gridLevels4326() throws Exception { BoundingBox bbox = new BoundingBox(175.0, 87.0, 180.0, 90.0); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 10); long[][] solution = { {1, 0, 1, 0, 0}, {3, 1, 3, 1, 1}, {7, 3, 7, 3, 2}, {15, 7, 15, 7, 3}, {31, 15, 31, 15, 4}, {63, 31, 63, 31, 5}, {126, 62, 127, 63, 6}, {252, 125, 255, 127, 7}, {504, 251, 511, 255, 8} }; for (int i = 0; i < solution.length; i++) { long[] bounds = grid.getCoverage(i); if (!Arrays.equals(solution[i], bounds)) { System.out.println(Arrays.toString(solution[i]) + " " + Arrays.toString(bounds)); } assertTrue(Arrays.equals(solution[i], bounds)); } }
public void testCoverageBounds() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 180, 90); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 0); long[] ret = grid.getCoverage(0); long[] correct = {1, 0, 1, 0, 0}; assertTrue(Arrays.equals(correct, ret)); }
public void testCoverageBounds2() throws Exception { BoundingBox bbox = new BoundingBox(0, 0, 180, 90); GridSubset grid = GridSubsetFactory.createGridSubSet(gridSetBroker.getWorldEpsg4326(), bbox, 0, 1); long[] ret = grid.getCoverage(1); long[] correct = {2, 1, 3, 1, 1}; assertTrue(Arrays.equals(correct, ret)); }
public void checkCoverage(long[] index) throws OutsideCoverageException { if (covers(index)) { return; } if (index[2] < getZoomStart() || index[2] > getZoomStop()) { throw new OutsideCoverageException(index, getZoomStart(), getZoomStop()); } long[] coverage = getCoverage((int) index[2]); throw new OutsideCoverageException(index, coverage); }