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 getNumTilesHigh(int zoomLevel) { return gridSet.getGridLevels()[zoomLevel].getNumTilesHigh(); }
public long getNumTilesWide(int zoomLevel) { return gridSet.getGridLevels()[zoomLevel].getNumTilesWide(); }
public BoundingBox getBounds() { int i; long tilesWide, tilesHigh; for (i = (getGridLevels().length - 1); i > 0; i--) { tilesWide = getGridLevels()[i].getNumTilesWide(); tilesHigh = getGridLevels()[i].getNumTilesHigh(); if (tilesWide == 1 && tilesHigh == 0) { break; } } tilesWide = getGridLevels()[i].getNumTilesWide(); tilesHigh = getGridLevels()[i].getNumTilesHigh(); long[] ret = {0, 0, tilesWide - 1, tilesHigh - 1, i}; return boundsFromRectangle(ret); }
public static GridSubset createGridSubSet(GridSet gridSet) { GridSubset ret = createGridSubSet( gridSet, gridSet.getOriginalExtent(), 0, gridSet.getGridLevels().length - 1); return ret; }
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; }
} else { Grid grid = getGridLevels()[gridIndex];
/** * 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; }
/** * 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; }
@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; }
public void testResolutionsAndScaleDenoms() { double[] resolutions = GridSubsetFactory.createGridSubSet(gridset).getResolutions(); List<LODInfo> lodInfos = cacheInfo.getTileCacheInfo().getLodInfos(); assertEquals(lodInfos.size(), resolutions.length); for (int i = 0; i < resolutions.length; i++) { LODInfo lodInfo = lodInfos.get(i); assertEquals(lodInfo.getResolution(), resolutions[i]); assertEquals( lodInfo.getScale(), gridset.getGridLevels()[i].getScaleDenominator(), 1e-6); } } }
/** 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()); }
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()); }
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"); }
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()); }
public void testLevels2() throws Exception { BoundingBox extent = new BoundingBox(0, 0, 1000, 1000); int levels = 16; int tileW = 300, tileH = 100; Double metersPerUnit = 1D; double pixelSize = GridSetFactory.DEFAULT_PIXEL_SIZE_METER; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getSRS(3005), extent, false, levels, metersPerUnit, pixelSize, tileW, tileH, false); assertEquals(extent, gridSet.getOriginalExtent()); Grid[] gridLevels = gridSet.getGridLevels(); assertEquals(16, gridLevels.length); assertEquals(1, gridLevels[0].getNumTilesWide()); assertEquals(3, gridLevels[0].getNumTilesHigh()); for (int i = 1; i < gridLevels.length; i++) { assertEquals(2 * gridLevels[i - 1].getNumTilesWide(), gridLevels[i].getNumTilesWide()); assertEquals(2 * gridLevels[i - 1].getNumTilesHigh(), gridLevels[i].getNumTilesHigh()); } }