Returns the EPSG:4326 bounding of the specified tile coordinate

@param tx        The tile x coordinate
@param ty        The tile y coordinate
@param zoomLevel The tile zoom level
@return the EPSG:4326 bounding box
4090
public Envelope tileBboxLngLat(int tx, int ty, int zoomLevel) {
        Coordinate topLeft = metersToLngLat(tileTopLeft(tx, ty, zoomLevel));
        Coordinate lowerRight = metersToLngLat(tileTopLeft(tx + 1, ty + 1, zoomLevel));
        Envelope result = new Envelope(topLeft, lowerRight);
        return result;
    }
745259
public <T> T getTile4LatLon( double lon, double lat, int zoom, Class<T> adaptee ) throws IOException {
        final int ty = MercatorProjection.latitudeToTileY(lat, (byte) zoom);
        final int tx = MercatorProjection.longitudeToTileX(lon, (byte) zoom);
        return getTile4TileCoordinate(ty, tx, zoom, adaptee);
    }
1321722
public static BoundingBox getWebMercatorBoundingBox(TileGrid tileGrid,
			int zoom) {

		double tileSize = tileSizeWithZoom(zoom);

		double minLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
				+ (tileGrid.getMinX() * tileSize);
		double maxLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
				+ ((tileGrid.getMaxX() + 1) * tileSize);
		double minLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
				- ((tileGrid.getMaxY() + 1) * tileSize);
		double maxLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
				- (tileGrid.getMinY() * tileSize);

		BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

		return box;
	}
21647
def _get_tile_when_web_mercator_crs(self, x_tile, y_tile, zoom,
                                        bands=None, masked=None,
                                        resampling=Resampling.cubic):
        
        roi = GeoVector.from_xyz(x_tile, y_tile, zoom)
        coordinates = roi.get_bounds(WEB_MERCATOR_CRS)
        window = self._window(coordinates, to_round=False)
        bands = bands or list(range(1, self.num_bands + 1))
        # we know the affine the result should produce becuase we know where
        # it is located by the xyz, therefore we calculate it here
        ratio = MERCATOR_RESOLUTION_MAPPING[zoom] / self.resolution()

        # the affine should be calculated before rounding the window values
        affine = self.window_transform(window)
        affine = affine * Affine.scale(ratio, ratio)

        window = Window(round(window.col_off),
                        round(window.row_off),
                        round(window.width),
                        round(window.height))
        return self.get_window(window, bands=bands, xsize=256, ysize=256, masked=masked, affine=affine)
733071
protected List<TileCode> calcCodesForBounds(Bbox bounds) {
		// Calculate tile width and height for tileLevel=currentTileLevel
		double div = Math.pow(2, currentTileLevel); // tile level must be correct!
		double scale = layer.getMapModel().getMapView().getCurrentScale();
		double tileWidth = Math.ceil((scale * layerBounds.getWidth()) / div) / scale;
		double tileHeight = Math.ceil((scale * layerBounds.getHeight()) / div) / scale;

		// For safety (to prevent division by 0):
		List<TileCode> codes = new ArrayList<TileCode>();
		if (tileWidth == 0 || tileHeight == 0) {
			return codes;
		}

		// Calculate bounds relative to extents:
		Bbox clippedBounds = bounds.intersection(layerBounds);
		if (clippedBounds == null) {
			Log.logError("Map bounds outside of layer extents, check the server configuration, it is incorrect.");
			return codes;
		}
		double relativeBoundX = Math.abs(clippedBounds.getX() - layerBounds.getX());
		double relativeBoundY = Math.abs(clippedBounds.getY() - layerBounds.getY());
		currentMinX = (int) Math.floor(relativeBoundX / tileWidth);
		currentMinY = (int) Math.floor(relativeBoundY / tileHeight);
		currentMaxX = (int) Math.ceil((relativeBoundX + clippedBounds.getWidth()) / tileWidth) - 1;
		currentMaxY = (int) Math.ceil((relativeBoundY + clippedBounds.getHeight()) / tileHeight) - 1;

		// Now fill the list with the correct codes:
		for (int x = currentMinX; x <= currentMaxX; x++) {
			for (int y = currentMinY; y <= currentMaxY; y++) {
				codes.add(new TileCode(currentTileLevel, x, y));
			}
		}
		return codes;
	}
717967
public static double getPixelXSize(BoundingBox webMercatorBoundingBox,
			long matrixWidth, int tileWidth) {
		double pixelXSize = (webMercatorBoundingBox.getMaxLongitude() - webMercatorBoundingBox
				.getMinLongitude()) / matrixWidth / tileWidth;
		return pixelXSize;
	}
1110404
function (level, x, y) {
            var context = null;
            if (level >= this.minLevel && level <= this.maxLevel) {
                context = this.levels[level].context2D;
            }
            return context;
        }
163334
public GeoPackageTile getTile(BoundingBox requestBoundingBox) {

		GeoPackageTile tile = null;

		// Transform to the projection of the tiles
		ProjectionTransform transformRequestToTiles = requestProjection
				.getTransformation(tilesProjection);
		BoundingBox tilesBoundingBox = requestBoundingBox
				.transform(transformRequestToTiles);

		List<TileMatrix> tileMatrices = getTileMatrices(tilesBoundingBox);

		for (int i = 0; tile == null && i < tileMatrices.size(); i++) {

			TileMatrix tileMatrix = tileMatrices.get(i);

			TileResultSet tileResults = retrieveTileResults(tilesBoundingBox,
					tileMatrix);
			if (tileResults != null) {

				try {

					if (tileResults.getCount() > 0) {

						BoundingBox requestProjectedBoundingBox = requestBoundingBox
								.transform(transformRequestToTiles);

						// Determine the requested tile dimensions, or use the
						// dimensions of a single tile matrix tile
						int requestedTileWidth = width != null ? width
								: (int) tileMatrix.getTileWidth();
						int requestedTileHeight = height != null ? height
								: (int) tileMatrix.getTileHeight();

						// Determine the size of the tile to initially draw
						int tileWidth = requestedTileWidth;
						int tileHeight = requestedTileHeight;
						if (!sameProjection) {
							tileWidth = (int) Math
									.round((requestProjectedBoundingBox
											.getMaxLongitude() - requestProjectedBoundingBox
											.getMinLongitude())
											/ tileMatrix.getPixelXSize());
							tileHeight = (int) Math
									.round((requestProjectedBoundingBox
											.getMaxLatitude() - requestProjectedBoundingBox
											.getMinLatitude())
											/ tileMatrix.getPixelYSize());
						}

						// Draw the resulting bitmap with the matching tiles
						GeoPackageTile geoPackageTile = drawTile(tileMatrix,
								tileResults, requestProjectedBoundingBox,
								tileWidth, tileHeight);

						// Create the tile
						if (geoPackageTile != null) {

							// Project the tile if needed
							if (!sameProjection
									&& geoPackageTile.getImage() != null) {
								BufferedImage reprojectTile = reprojectTile(
										geoPackageTile.getImage(),
										requestedTileWidth,
										requestedTileHeight,
										requestBoundingBox,
										transformRequestToTiles,
										tilesBoundingBox);
								geoPackageTile = new GeoPackageTile(
										requestedTileWidth,
										requestedTileHeight, reprojectTile);
							}

							tile = geoPackageTile;
						}

					}
				} finally {
					tileResults.close();
				}
			}
		}

		return tile;
	}
548296
def tileAddress(self, zoom, point):
        ""
        [x, y] = point
        assert x <= self.MAXX and x >= self.MINX
        assert y <= self.MAXY and y >= self.MINY
        assert zoom in range(0, len(self.RESOLUTIONS))

        tileS = self.tileSize(zoom)
        offsetX = abs(x - self.MINX)
        if self.originCorner == 'bottom-left':
            offsetY = abs(y - self.MINY)
        elif self.originCorner == 'top-left':
            offsetY = abs(self.MAXY - y)
        col = offsetX / tileS
        row = offsetY / tileS
        # We are exactly on the edge of a tile and the extent
        if x in (self.MINX, self.MAXX) and col.is_integer():
            col = max(0, col - 1)
        if y in (self.MINY, self.MAXY) and row.is_integer():
            row = max(0, row - 1)
        return [
            int(math.floor(col)),
            int(math.floor(row))
        ]
976765
public static Tile getUpperLeft(BoundingBox boundingBox, byte zoomLevel, int tileSize) {
        int tileLeft = MercatorProjection.longitudeToTileX(boundingBox.minLongitude, zoomLevel);
        int tileTop = MercatorProjection.latitudeToTileY(boundingBox.maxLatitude, zoomLevel);
        return new Tile(tileLeft, tileTop, zoomLevel, tileSize);
    }
762439
private static ProjectorBounds getBounds(String crs, String s, String version) {
		if (s == null)
			return null;
		String[] items = s.split(",");
		double minLong;
		double minLat;
		double maxLong;
		double maxLat;
		/**
		 * there is some confusion about order of bbox parameters. The OpenGIS
		 * WMS 1.3.0 spec says:
		 * http://portal.opengeospatial.org/files/?artifact_id=14416, 7.3.3.6:
		 * The value of the BBOX parameter in a GetMap request is a list of
		 * comma-separated real numbers (see 6.5) in the form
		 * "minx,miny,maxx,maxy". These values specify the minimum X, minimum Y,
		 * maximum X, and maximum Y values of a region in the Layer CRS of the
		 * request.
		 * 
		 * Yet, the GeoServer doco says:
		 * 
		 * http://docs.geoserver.org/stable/en/user/services/wms/basics.html
		 *
		 * Apparently the bbox parameter order is now that determined by the CRS
		 * definition. EPSG:3857 for instance has this in its WKT: AXIS [X,
		 * "EAST"] AXIS[Y,"NORTH"]. Still can't suss it but getting closer!
		 * 
		 **/

		if (("1.1.1".equals(version) || ("1.1.0".equals(version)) || !("CRS:84".equals(crs)))) {
			minLong = Double.parseDouble(items[0]);
			minLat = Double.parseDouble(items[1]);
			maxLong = Double.parseDouble(items[2]);
			maxLat = Double.parseDouble(items[3]);
		} else {
			// this is the order for CRS:84 but EPSG:4326 apparently not
			minLat = Double.parseDouble(items[0]);
			minLong = Double.parseDouble(items[1]);
			maxLat = Double.parseDouble(items[2]);
			maxLong = Double.parseDouble(items[3]);
		}
		ProjectorBounds bounds = new ProjectorBounds(crs, minLong, minLat, maxLong, maxLat);

		return bounds;
	}
600166
public static int pixelXToTileX(double pixelX, byte zoomLevel, int tileSize) {
        return (int) Math.min(Math.max(pixelX / tileSize, 0), Math.pow(2, zoomLevel) - 1);
    }
367921
public static BoundingBox getBoundingBox(int x, int y, int zoom) {

		int tilesPerSide = tilesPerSide(zoom);
		double tileWidthDegrees = tileWidthDegrees(tilesPerSide);
		double tileHeightDegrees = tileHeightDegrees(tilesPerSide);

		double minLon = -180.0 + (x * tileWidthDegrees);
		double maxLon = minLon + tileWidthDegrees;

		double maxLat = 90.0 - (y * tileHeightDegrees);
		double minLat = maxLat - tileHeightDegrees;

		BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

		return box;
	}
1001495
public BufferedImage drawTile(int x, int y, int zoom) {
		BufferedImage image;
		if (isIndexQuery()) {
			image = drawTileQueryIndex(x, y, zoom);
		} else {
			image = drawTileQueryAll(x, y, zoom);
		}
		return image;
	}
586627
public Coordinate pixelsToMeters(double px, double py, int zoomLevel) {
        double res = resolution(zoomLevel);
        double mx = px * res - originShift;
        double my = -py * res + originShift;

        return new Coordinate(mx, my);
    }
149392
public static BoundingBox getWGS84BoundingBox(TileGrid tileGrid, int zoom) {

		int tilesPerLat = tilesPerWGS84LatSide(zoom);
		int tilesPerLon = tilesPerWGS84LonSide(zoom);

		double tileSizeLat = tileSizeLatPerWGS84Side(tilesPerLat);
		double tileSizeLon = tileSizeLonPerWGS84Side(tilesPerLon);

		double minLon = (-1 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)
				+ (tileGrid.getMinX() * tileSizeLon);
		double maxLon = (-1 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)
				+ ((tileGrid.getMaxX() + 1) * tileSizeLon);
		double minLat = ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT
				- ((tileGrid.getMaxY() + 1) * tileSizeLat);
		double maxLat = ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT
				- (tileGrid.getMinY() * tileSizeLat);

		BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

		return box;
	}
1079140
protected BaseTile getFringeTile (int tx, int ty)
    {
        SceneBlock block = getBlock(tx, ty);
        return (block == null) ? null : block.getFringeTile(tx, ty);
    }