protected void determineSourceResolution() { xResolution = reqBounds.getWidth() / reqWidth; yResolution = reqBounds.getHeight() / reqHeight; double tmpResolution; // We use the smallest one if (yResolution < xResolution) { tmpResolution = yResolution; } else { tmpResolution = xResolution; } log.debug("x res: " + xResolution + " y res: " + yResolution + " tmpResolution: " + tmpResolution); // Cut ourselves 0.5% slack double compResolution = 1.005 * tmpResolution; double[] resArray = gridSubset.getResolutions(); for (srcIdx = 0; srcIdx < resArray.length; srcIdx++) { srcResolution = resArray[srcIdx]; if (srcResolution < compResolution) { break; } } if (srcIdx >= resArray.length) { srcIdx = resArray.length - 1; } log.debug("z: " + srcIdx + " , resolution: " + srcResolution + " (" + tmpResolution + ")"); // At worst, we have the best resolution possible }
protected void determineSourceResolution() { xResolution = reqBounds.getWidth() / reqWidth; yResolution = reqBounds.getHeight() / reqHeight;
protected void determineCanvasLayout() { srcRectangle = gridSubset.getCoverageIntersection(srcIdx, reqBounds); srcBounds = gridSubset.boundsFromRectangle(srcRectangle); // We now have the complete area, lets figure out our offsets // Positive means that there is blank space to the first tile, // negative means we will not use the entire tile boundOfs[0] = srcBounds.getMinX() - reqBounds.getMinX(); boundOfs[1] = srcBounds.getMinY() - reqBounds.getMinY(); boundOfs[2] = reqBounds.getMaxX() - srcBounds.getMaxX(); boundOfs[3] = reqBounds.getMaxY() - srcBounds.getMaxY(); canvasSize[0] = (int) Math.round(reqBounds.getWidth() / this.srcResolution); canvasSize[1] = (int) Math.round(reqBounds.getHeight() / this.srcResolution); // Calculate the corresponding pixel offsets. We'll stick to sane, // i.e. bottom left, coordinates at this point for (int i = 0; i < 4; i++) { canvOfs[i] = (int) Math.round(boundOfs[i] / this.srcResolution); } if (log.isDebugEnabled()) { log.debug("intersection rectangle: " + Arrays.toString(srcRectangle)); log.debug("intersection bounds: " + srcBounds + " (" + reqBounds + ")"); log.debug("Bound offsets: " + Arrays.toString(boundOfs)); log.debug("Canvas size: " + Arrays.toString(canvasSize) + "(" + reqWidth + "," + reqHeight + ")"); log.debug("Canvas offsets: " + Arrays.toString(canvOfs)); } }
canvasSize[1] = (int) Math.round(reqBounds.getHeight() / this.srcResolution);
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); }
@Test public void testTileFuserSecurity() throws Exception { Mockito.doThrow(new SecurityException()).when(secDisp).checkSecurity(Mockito.any()); TileLayer layer = createWMSLayer(); // request fits inside -30.0,15.0,45.0,30 BoundingBox bounds = new BoundingBox(-25.0, 17.0, 40.0, 22); // One in between int width = (int) bounds.getWidth() * 10; int height = (int) bounds.getHeight() * 10; GridSubset gridSubset = layer.getGridSubset(layer.getGridSubsets().iterator().next()); TileLayerDispatcher tld = mock(TileLayerDispatcher.class); StorageBroker sb = mock(StorageBroker.class); Mockito.when(tld.getTileLayer("test:layer")).thenReturn(layer); WMSTileFuser tileFuser = new WMSTileFuser(tld, sb, fuserRequest(layer, gridSubset, bounds, width, height)); tileFuser.setSecurityDispatcher(secDisp); MockHttpServletResponse response = new MockHttpServletResponse(); RuntimeStats stats = mock(RuntimeStats.class); exception.expect(SecurityException.class); tileFuser.writeResponse(response, stats); }
@Test public void testTileFuserSuperset() throws Exception { TileLayer layer = createWMSLayer(); // request larger than -30.0,15.0,45.0,30 BoundingBox bounds = new BoundingBox(-35.0, 14.0, 55.0, 39); // One in between int width = (int) bounds.getWidth() * 25; int height = (int) bounds.getHeight() * 25; GridSubset gridSubset = layer.getGridSubset(layer.getGridSubsets().iterator().next()); TileLayerDispatcher tld = mock(TileLayerDispatcher.class); Mockito.when(tld.getTileLayer("test:layer")).thenReturn(layer); StorageBroker sb = mock(StorageBroker.class); WMSTileFuser tileFuser = new WMSTileFuser(tld, sb, fuserRequest(layer, gridSubset, bounds, width, height)); tileFuser.setSecurityDispatcher(secDisp); tileFuser.determineSourceResolution(); tileFuser.determineCanvasLayout(); }
double y = coverageBounds.getMinY(); double width = coverageBounds.getWidth(); double height = coverageBounds.getHeight(); genvelope.setFrame(x, y, width, height);
int height = (int) bounds.getHeight() * 10; GridSubset gridSubset = layer.getGridSubset(layer.getGridSubsets().iterator().next()); TileLayerDispatcher tld = mock(TileLayerDispatcher.class);
double y = coverageBounds.getMinY(); double width = coverageBounds.getWidth(); double height = coverageBounds.getHeight(); genvelope.setFrame(x, y, width, height);
int height = (int) bounds.getHeight() * 25; layer.getGridSubset(layer.getGridSubsets().iterator().next()); File temp = File.createTempFile("gwc", "wms");
double coordHeight = metaBbox.getHeight();
public void testIntersection() throws Exception { BoundingBox bb1 = new BoundingBox(0, 0, 10, 10); BoundingBox bb2 = new BoundingBox(5, 5, 20, 20); BoundingBox intersection = BoundingBox.intersection(bb1, bb2); assertNotNull(intersection); assertEquals(5D, intersection.getWidth()); assertEquals(5D, intersection.getHeight()); assertTrue(intersection.isSane()); assertTrue(Arrays.equals(new double[] {5, 5, 10, 10}, intersection.getCoords())); }
@Test public void testTileFuserSubset() throws Exception { TileLayer layer = createWMSLayer(); // request fits inside -30.0,15.0,45.0,30 BoundingBox bounds = new BoundingBox(-25.0, 17.0, 40.0, 22); // One in between int width = (int) bounds.getWidth() * 10; int height = (int) bounds.getHeight() * 10; GridSubset gridSubset = layer.getGridSubset(layer.getGridSubsets().iterator().next()); TileLayerDispatcher tld = mock(TileLayerDispatcher.class); Mockito.when(tld.getTileLayer("test:layer")).thenReturn(layer); StorageBroker sb = mock(StorageBroker.class); WMSTileFuser tileFuser = new WMSTileFuser(tld, sb, fuserRequest(layer, gridSubset, bounds, width, height)); tileFuser.setSecurityDispatcher(secDisp); tileFuser.determineSourceResolution(); tileFuser.determineCanvasLayout(); assertTrue(tileFuser.srcBounds.contains(bounds)); WMSTileFuser.PixelOffsets comparison = new WMSTileFuser.PixelOffsets(); // -228, -193, -56, -6 comparison.left = -228; comparison.bottom = -193; comparison.right = -56; comparison.top = -6; assertEquals(comparison.left, tileFuser.canvOfs.left); assertEquals(comparison.bottom, tileFuser.canvOfs.bottom); assertEquals(comparison.right, tileFuser.canvOfs.right); assertEquals(comparison.top, tileFuser.canvOfs.top); }
int height = (int) bounds.getHeight() * 10; GridSubset gridSubset = layer.getGridSubset(layer.getGridSubsets().iterator().next()); TileLayerDispatcher tld = mock(TileLayerDispatcher.class);