@Override public boolean equals(Object obj) { if (!(obj instanceof GridSet)) return false; GridSet other = (GridSet) obj; if (this == other) return true; boolean equals = ObjectUtils.equals(getSrs(), other.getSrs()) && ObjectUtils.equals(getName(), other.getName()) && ObjectUtils.equals(getDescription(), other.getDescription()) && ObjectUtils.equals(getTileWidth(), other.getTileWidth()) && ObjectUtils.equals(getTileHeight(), other.getTileHeight()) && ObjectUtils.equals(isTopLeftAligned(), other.isTopLeftAligned()) && ObjectUtils.equals(isyCoordinateFirst(), other.isyCoordinateFirst()) && ObjectUtils.equals(getOriginalExtent(), other.getOriginalExtent()) && Arrays.equals(getGridLevels(), other.getGridLevels()); return equals; }
@Override public double getScaleDenominator(int level) { if(level<0) return Double.POSITIVE_INFINITY; if(level>=gridset.getNumLevels()) return 0; return gridset.getGrid(level).getScaleDenominator(); }
boolean needsTruncate = !getBounds().equals(another.getBounds()); needsTruncate |= isTopLeftAligned() != another.isTopLeftAligned(); needsTruncate |= getTileWidth() != another.getTileWidth(); needsTruncate |= getTileHeight() != another.getTileHeight(); needsTruncate |= !getSrs().equals(another.getSrs()); Grid[] myGrids = getGridLevels(); Grid[] otherGrids = another.getGridLevels(); if (myGrids.length > otherGrids.length) { return true;
public void checkTileDimensions(int width, int height) throws TileDimensionsMismatchException { if (width != gridSet.getTileWidth() || height != gridSet.getTileHeight()) { throw new TileDimensionsMismatchException( width, height, gridSet.getTileWidth(), gridSet.getTileWidth()); } }
public static GridSubset createGridSubSet(GridSet gridSet) { GridSubset ret = createGridSubSet( gridSet, gridSet.getOriginalExtent(), 0, gridSet.getGridLevels().length - 1); return ret; }
public String getName() { return gridSet.getName(); }
static class CustomLayerImplementation { private String name; private String title; private boolean isAuthorized; private List<String> formats; public CustomLayerImplementation( String name, String title, boolean isAuthorized, List<String> formats) { this.name = name; this.title = title; this.isAuthorized = isAuthorized; this.formats = formats; } }
/** Builds an XMLGridSet from a GridSet */ public XMLGridSet(GridSet gset) { setAlignTopLeft(gset.isTopLeftAligned()); setYCoordinateFirst(gset.isyCoordinateFirst()); setExtent(gset.getOriginalExtent()); setLevels(null); if (gset.isResolutionsPreserved()) { setResolutions(resolutions(gset.getGridLevels())); setScaleDenominators(null); } else { setResolutions(null); setScaleDenominators(scaleDenominators(gset.getGridLevels())); } setMetersPerUnit(gset.getMetersPerUnit()); setName(gset.getName()); setDescription(gset.getDescription()); setPixelSize(gset.getPixelSize()); setScaleNames(scaleNames(gset.getGridLevels())); setSrs(gset.getSrs()); setTileWidth(gset.getTileWidth()); setTileHeight(gset.getTileHeight()); }
private void tileMatrixSet(XMLBuilder xml, GridSet gridSet) throws IOException { xml.indentElement("TileMatrixSet"); xml.simpleElement("ows:Identifier", gridSet.getName(), true); // If the following is not good enough, please get in touch and we will try to fix it :) xml.simpleElement( "ows:SupportedCRS", "urn:ogc:def:crs:EPSG::" + gridSet.getSrs().getNumber(), true); // TODO detect these str.append(" // <WellKnownScaleSet>urn:ogc:def:wkss:GlobalCRS84Pixel</WellKnownScaleSet>\n"); Grid[] grids = gridSet.getGridLevels(); for (int i = 0; i < grids.length; i++) { double[] tlCoordinates = gridSet.getOrderedTopLeftCorner(i); tileMatrix( xml, grids[i], tlCoordinates, gridSet.getTileWidth(), gridSet.getTileHeight(), gridSet.isScaleWarning()); } xml.endElement("TileMatrixSet"); }
@Override protected Matcher<GridSet> infoEquals(GridSet expected) { return new CustomMatcher<GridSet>( "GridSet matching " + expected.getName() + " with " + expected.getDescription()) { @Override public boolean matches(Object item) { return item instanceof GridSet && ((GridSet) item).getName().equals(((GridSet) expected).getName()) && ((GridSet) item) .getDescription() .equals(((GridSet) expected).getDescription()); } }; }
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()); }
false); assertEquals("test", gridSet.getName()); assertEquals(0D, gridSet.tileOrigin()[0]); assertEquals(0D, gridSet.tileOrigin()[1]); assertEquals(new BoundingBox(0, 0, 100, 50), gridSet.getBounds()); assertEquals(4, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; false); assertEquals(new BoundingBox(0, -5, 100, 45), gridSet.getBounds()); assertEquals("test", gridSet.getName()); assertEquals(0D, gridSet.tileOrigin()[0]); assertEquals(45D, gridSet.tileOrigin()[1]);
final boolean needsTruncate = oldGridSet.shouldTruncateIfChanged(newGridSet); if (needsTruncate) { log.warning("### Changes in gridset force truncation of affected Tile layers"); final boolean sameSRS = oldGridSet.getSrs().equals(newGridSet.getSrs()); final int maxZoomLevel = newGridSet.getNumLevels() - 1; gridSetExtent = newGridSet.getOriginalExtent().intersection(gridSetExtent);
final Grid[] gridLevels = gridSet.getGridLevels(); final int maxLevel = gridLevels.length - 1; if (zoomStart == null) { + zoomStop + " for GridSet " + gridSet.getName() + " whose max zoom level is " + maxLevel coverage = new long[] {0, 0, maxColX, maxColY, z}; } else { coverage = gridSet.closestRectangle(z, extent); BoundingBox gridSetBounds = gridSet.getBounds(); if (extent == null || extent.contains(gridSetBounds)) { fullCoverage = true;
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; }
if (null == extent) { try { SRS srs = gridSet.getSrs(); try { extent = getBounds(srs); LOGGER.warning(msg); extent = gridSet.getBounds(); BoundingBox maxBounds = gridSet.getBounds(); BoundingBox intersection = maxBounds.intersection(extent); extent = intersection; LOGGER.log(Level.WARNING, "Error computing layer bounds, assuming whole GridSet bounds", e); extent = gridSet.getOriginalExtent();
public static byte[] createFakeSourceImage(final WMSLayer layer) throws IOException { int tileWidth = layer.getGridSubset(gridSetBroker.getWorldEpsg4326().getName()) .getGridSet() .getTileWidth(); int tileHeight = layer.getGridSubset(gridSetBroker.getWorldEpsg4326().getName()) .getGridSet() .getTileHeight(); int width = tileWidth * layer.getMetaTilingFactors()[0]; int height = tileHeight * layer.getMetaTilingFactors()[1]; ByteArrayOutputStream out = new ByteArrayOutputStream(); RenderedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); String formatName = layer.getMimeTypes().get(0).getInternalName(); ImageIO.write(image, formatName, out); return out.toByteArray(); }
private void validateGridSet(GridSet gridSet) { if (Objects.isNull(gridSet.getName())) { throw new IllegalArgumentException("GridSet name is not set"); } if (Objects.isNull(gridSet.getGridLevels())) { throw new IllegalArgumentException("GridSet has no levels"); } }
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); }
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; }