/** * Gets the geographic extend of this Tile as a BoundingBox. * * @return boundaries of this tile. */ public BoundingBox getBoundingBox() { if (this.boundingBox == null) { double minLatitude = Math.max(MercatorProjection.LATITUDE_MIN, MercatorProjection.tileYToLatitude(tileY + 1, zoomLevel)); double minLongitude = Math.max(-180, MercatorProjection.tileXToLongitude(this.tileX, zoomLevel)); double maxLatitude = Math.min(MercatorProjection.LATITUDE_MAX, MercatorProjection.tileYToLatitude(this.tileY, zoomLevel)); double maxLongitude = Math.min(180, MercatorProjection.tileXToLongitude(tileX + 1, zoomLevel)); if (maxLongitude == -180) { // fix for dateline crossing, where the right tile starts at -180 and causes an invalid bbox maxLongitude = 180; } this.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude); } return this.boundingBox; }
@Test public void tileYToLatitudeTest() { for (int tileSize : TILE_SIZES) { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { double latitude = MercatorProjection.tileYToLatitude(0, zoomLevel); Assert.assertEquals(MercatorProjection.LATITUDE_MAX, latitude, 0); latitude = MercatorProjection.tileYToLatitudeWithScaleFactor(0, MercatorProjection.zoomLevelToScaleFactor(zoomLevel)); Assert.assertEquals(MercatorProjection.LATITUDE_MAX, latitude, 0); long tileY = MercatorProjection.getMapSize(zoomLevel, tileSize) / tileSize; latitude = MercatorProjection.tileYToLatitude(tileY, zoomLevel); Assert.assertEquals(MercatorProjection.LATITUDE_MIN, latitude, 0); tileY = MercatorProjection.getMapSizeWithScaleFactor(MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize) / tileSize; latitude = MercatorProjection.tileYToLatitudeWithScaleFactor(tileY, MercatorProjection.zoomLevelToScaleFactor(zoomLevel)); Assert.assertEquals(MercatorProjection.LATITUDE_MIN, latitude, 0); } } }
private static double[] bufferInDegrees(long tileY, byte zoom, int enlargementInMeter) { if (enlargementInMeter == 0) { return EPSILON_ZERO; } double[] epsilons = new double[2]; double lat = MercatorProjection.tileYToLatitude(tileY, zoom); epsilons[0] = LatLongUtils.latitudeDistance(enlargementInMeter); epsilons[1] = LatLongUtils.longitudeDistance(enlargementInMeter, lat); return epsilons; }
private static Geometry tileToJTSGeometry(long tileX, long tileY, byte zoom, int enlargementInMeter) { double minLat = MercatorProjection.tileYToLatitude(tileY + 1, zoom); double maxLat = MercatorProjection.tileYToLatitude(tileY, zoom); double minLon = MercatorProjection.tileXToLongitude(tileX, zoom); double maxLon = MercatorProjection.tileXToLongitude(tileX + 1, zoom); double[] epsilons = bufferInDegrees(tileY, zoom, enlargementInMeter); minLon -= epsilons[1]; minLat -= epsilons[0]; maxLon += epsilons[1]; maxLat += epsilons[0]; Coordinate bottomLeft = new Coordinate(minLon, minLat); Coordinate topRight = new Coordinate(maxLon, maxLat); return GEOMETRY_FACTORY.createLineString(new Coordinate[]{bottomLeft, topRight}).getEnvelope(); }
private static double calculatePriority(Tile tile, MapPosition mapPosition, int tileSize) { double tileLatitude = MercatorProjection.tileYToLatitude(tile.tileY, tile.zoomLevel); double tileLongitude = MercatorProjection.tileXToLongitude(tile.tileX, tile.zoomLevel); int halfTileSize = tileSize / 2; long mapSize = MercatorProjection.getMapSize(mapPosition.zoomLevel, tileSize); double tilePixelX = MercatorProjection.longitudeToPixelX(tileLongitude, mapSize) + halfTileSize; double tilePixelY = MercatorProjection.latitudeToPixelY(tileLatitude, mapSize) + halfTileSize; LatLong latLong = mapPosition.latLong; double mapPixelX = MercatorProjection.longitudeToPixelX(latLong.longitude, mapSize); double mapPixelY = MercatorProjection.latitudeToPixelY(latLong.latitude, mapSize); double diffPixel = Math.hypot(tilePixelX - mapPixelX, tilePixelY - mapPixelY); int diffZoom = Math.abs(tile.zoomLevel - mapPosition.zoomLevel); return diffPixel + PENALTY_PER_ZOOM_LEVEL * tileSize * diffZoom; }
/** * @param latLong the point * @param tile the tile * @return true if the point is located in the given tile */ public static boolean pointInTile(LatLong latLong, TileCoordinate tile) { if (latLong == null || tile == null) { return false; } double lon1 = MercatorProjection.tileXToLongitude(tile.getX(), tile.getZoomlevel()); double lon2 = MercatorProjection.tileXToLongitude(tile.getX() + 1, tile.getZoomlevel()); double lat1 = MercatorProjection.tileYToLatitude(tile.getY(), tile.getZoomlevel()); double lat2 = MercatorProjection.tileYToLatitude(tile.getY() + 1, tile.getZoomlevel()); return latLong.latitude <= lat1 && latLong.latitude >= lat2 && latLong.longitude >= lon1 && latLong.longitude <= lon2; }
double tileLatitude = MercatorProjection.tileYToLatitude(subFileParameter.boundaryTileTop + row, subFileParameter.baseZoomLevel); double tileLongitude = MercatorProjection.tileXToLongitude(subFileParameter.boundaryTileLeft + column,
tileCoordinate.getY()); final int currentTileLat = LatLongUtils.degreesToMicrodegrees(MercatorProjection.tileYToLatitude( tileCoordinate.getY(), tileCoordinate.getZoomlevel())); final int currentTileLon = LatLongUtils.degreesToMicrodegrees(MercatorProjection.tileXToLongitude(
/** * Gets the geographic extend of this Tile as a BoundingBox. * * @return boundaries of this tile. */ public BoundingBox getBoundingBox() { if (this.boundingBox == null) { double minLatitude = Math.max(MercatorProjection.LATITUDE_MIN, MercatorProjection.tileYToLatitude(tileY + 1, zoomLevel)); double minLongitude = Math.max(-180, MercatorProjection.tileXToLongitude(this.tileX, zoomLevel)); double maxLatitude = Math.min(MercatorProjection.LATITUDE_MAX, MercatorProjection.tileYToLatitude(this.tileY, zoomLevel)); double maxLongitude = Math.min(180, MercatorProjection.tileXToLongitude(tileX + 1, zoomLevel)); if (maxLongitude == -180) { // fix for dateline crossing, where the right tile starts at -180 and causes an invalid bbox maxLongitude = 180; } this.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude); } return this.boundingBox; }
private static double calculatePriority(Tile tile, MapPosition mapPosition, int tileSize) { double tileLatitude = MercatorProjection.tileYToLatitude(tile.tileY, tile.zoomLevel); double tileLongitude = MercatorProjection.tileXToLongitude(tile.tileX, tile.zoomLevel); int halfTileSize = tileSize / 2; long mapSize = MercatorProjection.getMapSize(mapPosition.zoomLevel, tileSize); double tilePixelX = MercatorProjection.longitudeToPixelX(tileLongitude, mapSize) + halfTileSize; double tilePixelY = MercatorProjection.latitudeToPixelY(tileLatitude, mapSize) + halfTileSize; LatLong latLong = mapPosition.latLong; double mapPixelX = MercatorProjection.longitudeToPixelX(latLong.longitude, mapSize); double mapPixelY = MercatorProjection.latitudeToPixelY(latLong.latitude, mapSize); double diffPixel = Math.hypot(tilePixelX - mapPixelX, tilePixelY - mapPixelY); int diffZoom = Math.abs(tile.zoomLevel - mapPosition.zoomLevel); return diffPixel + PENALTY_PER_ZOOM_LEVEL * tileSize * diffZoom; }
double tileLatitude = MercatorProjection.tileYToLatitude(subFileParameter.boundaryTileTop + row, subFileParameter.baseZoomLevel); double tileLongitude = MercatorProjection.tileXToLongitude(subFileParameter.boundaryTileLeft + column,