private static double[] scaleDenominators(Grid[] grids) { double[] scales = new double[grids.length]; for (int i = 0; i < scales.length; i++) { scales[i] = grids[i].getScaleDenominator(); } return scales; }
/** * 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; }
public long[][] expandToMetaFactors(final long[][] coverages, final int[] metaFactors) { long[][] ret = ServletUtils.arrayDeepCopy(coverages); for (long[] cov : ret) { final int z = (int) cov[4]; final Grid grid = this.gridSet.getGrid(z); final long numTilesWide = grid.getNumTilesWide(); final long numTilesHigh = grid.getNumTilesHigh(); cov[0] = cov[0] - (cov[0] % metaFactors[0]); cov[1] = cov[1] - (cov[1] % metaFactors[1]); cov[2] = cov[2] - (cov[2] % metaFactors[0]) + (metaFactors[0] - 1); if (cov[2] > numTilesWide) { cov[2] = numTilesWide; } cov[3] = cov[3] - (cov[3] % metaFactors[1]) + (metaFactors[1] - 1); if (cov[3] > numTilesHigh) { cov[3] = numTilesHigh; } } return ret; }
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 tileMatrix( XMLBuilder xml, Grid grid, double[] tlCoordinates, int tileWidth, int tileHeight, boolean scaleWarning) throws IOException { xml.indentElement("TileMatrix"); if (scaleWarning) { xml.simpleElement( "ows:Abstract", "The grid was not well-defined, the scale therefore assumes 1m per map unit.", true); } xml.simpleElement("ows:Identifier", grid.getName(), true); xml.simpleElement("ScaleDenominator", Double.toString(grid.getScaleDenominator()), true); xml.indentElement("TopLeftCorner") .text(Double.toString(tlCoordinates[0])) .text(" ") .text(Double.toString(tlCoordinates[1])) .endElement(); xml.simpleElement("TileWidth", Integer.toString(tileWidth), true); xml.simpleElement("TileHeight", Integer.toString(tileHeight), true); xml.simpleElement("MatrixWidth", Long.toString(grid.getNumTilesWide()), true); xml.simpleElement("MatrixHeight", Long.toString(grid.getNumTilesHigh()), true); xml.endElement("TileMatrix"); }
Grid curGrid = new Grid(); curGrid.setScaleDenominator(scaleDenoms[i]); curGrid.setResolution(pixelSize * (scaleDenoms[i] / gridSet.getMetersPerUnit())); } else { curGrid.setResolution(resolutions[i]); curGrid.setScaleDenominator( (resolutions[i] * gridSet.getMetersPerUnit()) / DEFAULT_PIXEL_SIZE_METER); final double mapUnitWidth = tileWidth * curGrid.getResolution(); final double mapUnitHeight = tileHeight * curGrid.getResolution(); (long) Math.ceil((extent.getHeight() - mapUnitHeight * 0.01) / mapUnitHeight); curGrid.setNumTilesWide(tilesWide); curGrid.setNumTilesHigh(tilesHigh); curGrid.setName(gridSet.getName() + ":" + i); } else { curGrid.setName(scaleNames[i]);
public long getNumTilesHigh(int zoomLevel) { return gridSet.getGridLevels()[zoomLevel].getNumTilesHigh(); }
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 long getNumTilesWide(int zoomLevel) { return gridSet.getGridLevels()[zoomLevel].getNumTilesWide(); }
private static String[] scaleNames(Grid[] grids) { String[] scaleNames = new String[grids.length]; for (int i = 0; i < scaleNames.length; i++) { scaleNames[i] = grids[i].getName(); } return scaleNames; }
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()); }
long coverageMaxY = grid.getNumTilesHigh() - 1;
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; }
public String[] getGridNames() { List<String> ret = new ArrayList<String>(gridCoverageLevels.size()); final int zoomStart = getZoomStart(); final int zoomStop = getZoomStop(); for (int i = zoomStart; i <= zoomStop; i++) { ret.add(gridSet.getGrid(i).getName()); } return ret.toArray(new String[ret.size()]); }
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 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; }
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); }
@Override public double getScaleDenominator(int level) { if(level<0) return Double.POSITIVE_INFINITY; if(level>=gridset.getNumLevels()) return 0; return gridset.getGrid(level).getScaleDenominator(); }
long bottomRow = grid.getNumTilesHigh() - 1; // The WMST row number for the bottom row
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); }