public long getNumTilesHigh(int zoomLevel) { return gridSet.getGridLevels()[zoomLevel].getNumTilesHigh(); }
long coverageMaxY = grid.getNumTilesHigh() - 1;
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 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); }
long bottomRow = grid.getNumTilesHigh() - 1; // The WMST row number for the bottom row
/** * 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; }
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; }
/** * 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; }
double dGridExtent = grid.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"); }
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; }
long coverageMaxY = grid.getNumTilesHigh() - 1;
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()); }
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()); } }
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()); }
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 void testResolutionsArrayEPSG4326() throws Exception { BoundingBox extent = new BoundingBox(-180, -90, 180, 90); double[] resolutions = {180.0 / 256, 180.0 / 512, 180.0 / 1024, 180.0 / 2048}; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, resolutions, null, null, 0.00028, null, 256, 256, false); assertEquals("test", gridSet.getName()); assertEquals(-180.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(resolutions.length, 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 void testResolutionsArrayTricky1() throws Exception { // This should be expanded in the X direction BoundingBox extent = new BoundingBox(-173, -90, 180, 96); double[] resolutions = {180.0 / 200, 180.0 / 400, 180.0 / 800}; GridSet gridSet = GridSetFactory.createGridSet( "test", SRS.getEPSG4326(), extent, false, resolutions, null, null, 0.00028, null, 200, 200, false); assertEquals(-173.0, gridSet.tileOrigin()[0]); assertEquals(-90.0, gridSet.tileOrigin()[1]); assertEquals(resolutions.length, gridSet.getGridLevels().length); Grid grid0 = gridSet.getGridLevels()[0]; assertEquals(180.0 / 200, grid0.getResolution()); assertEquals(2L, grid0.getNumTilesWide()); assertEquals(2L, grid0.getNumTilesHigh()); Grid grid3 = gridSet.getGridLevels()[2]; assertEquals(180.0 / 800, grid3.getResolution()); assertEquals(8L, grid3.getNumTilesWide()); assertEquals(5L, grid3.getNumTilesHigh()); }
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()); }