Java Code Examples for mil.nga.geopackage.BoundingBox#getMinLatitude()
The following examples show how to use
mil.nga.geopackage.BoundingBox#getMinLatitude() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 6 votes |
/** * Bound the upper and lower bounds of the degrees bounding box with web * mercator limits * * @param boundingBox * degrees bounding box * @return bounding box * @since 1.3.1 */ public static BoundingBox boundDegreesBoundingBoxWithWebMercatorLimits( BoundingBox boundingBox) { BoundingBox bounded = new BoundingBox(boundingBox); if (bounded .getMinLatitude() < ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE) { bounded.setMinLatitude( ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE); } if (bounded .getMaxLatitude() < ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE) { bounded.setMaxLatitude( ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE); } if (bounded .getMaxLatitude() > ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE) { bounded.setMaxLatitude( ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE); } if (bounded .getMinLatitude() > ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE) { bounded.setMinLatitude( ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE); } return bounded; }
Example 2
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 6 votes |
/** * Get the tile row of the latitude in constant units * * @param totalBox * total bounding box * @param matrixHeight * matrix height * @param latitude * in constant units * @return tile row if in the range, -1 if before, * {@link TileMatrix#getMatrixHeight()} if after */ public static long getTileRow(BoundingBox totalBox, long matrixHeight, double latitude) { double minY = totalBox.getMinLatitude(); double maxY = totalBox.getMaxLatitude(); long tileId; if (latitude <= minY) { tileId = matrixHeight; } else if (latitude > maxY) { tileId = -1; } else { double matrixHeightMeters = totalBox.getMaxLatitude() - totalBox.getMinLatitude(); double tileHeight = matrixHeightMeters / matrixHeight; tileId = (long) ((maxY - latitude) / tileHeight); } return tileId; }
Example 3
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 5 votes |
/** * Get the tile grid that includes the entire tile bounding box * * @param webMercatorBoundingBox * web mercator bounding box * @param zoom * zoom level * @return tile grid */ public static TileGrid getTileGrid(BoundingBox webMercatorBoundingBox, int zoom) { int tilesPerSide = tilesPerSide(zoom); double tileSize = tileSize(tilesPerSide); int minX = (int) ((webMercatorBoundingBox.getMinLongitude() + ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH) / tileSize); double tempMaxX = (webMercatorBoundingBox.getMaxLongitude() + ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH) / tileSize; int maxX = (int) (tempMaxX - ProjectionConstants.WEB_MERCATOR_PRECISION); maxX = Math.min(maxX, tilesPerSide - 1); int minY = (int) (((webMercatorBoundingBox.getMaxLatitude() - ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH) * -1) / tileSize); double tempMaxY = ((webMercatorBoundingBox.getMinLatitude() - ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH) * -1) / tileSize; int maxY = (int) (tempMaxY - ProjectionConstants.WEB_MERCATOR_PRECISION); maxY = Math.min(maxY, tilesPerSide - 1); TileGrid grid = new TileGrid(minX, minY, maxX, maxY); return grid; }
Example 4
Source File: TileDao.java From geopackage-java with MIT License | 5 votes |
/** * Determine if the tiles are in the XYZ tile coordinate format * * @return true if XYZ tile format * @since 3.5.0 */ public boolean isXYZTiles() { // Convert the bounding box to wgs84 BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); BoundingBox wgs84BoundingBox = boundingBox .transform(projection.getTransformation( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)); boolean xyzTiles = false; // Verify the bounds are the entire world if (wgs84BoundingBox .getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE && wgs84BoundingBox .getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE && wgs84BoundingBox .getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && wgs84BoundingBox .getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) { xyzTiles = true; // Verify each tile matrix is the correct width and height for (TileMatrix tileMatrix : tileMatrices) { long zoomLevel = tileMatrix.getZoomLevel(); long tilesPerSide = TileBoundingBoxUtils .tilesPerSide((int) zoomLevel); if (tileMatrix.getMatrixWidth() != tilesPerSide || tileMatrix.getMatrixHeight() != tilesPerSide) { xyzTiles = false; break; } } } return xyzTiles; }
Example 5
Source File: CoverageData.java From geopackage-java with MIT License | 5 votes |
/** * Get the tile matrix for the zoom level as defined by the area of the * request * * @param request * coverage data request * @return tile matrix or null */ private TileMatrix getTileMatrix(CoverageDataRequest request) { TileMatrix tileMatrix = null; // Check if the request overlaps coverage data bounding box if (request.overlap(coverageBoundingBox) != null) { // Get the tile distance BoundingBox projectedBoundingBox = request .getProjectedBoundingBox(); double distanceWidth = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); double distanceHeight = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); // Get the zoom level to request based upon the tile size Long zoomLevel = tileDao.getClosestZoomLevel(distanceWidth, distanceHeight); // If there is a matching zoom level if (zoomLevel != null) { tileMatrix = tileDao.getTileMatrix(zoomLevel); } } return tileMatrix; }
Example 6
Source File: TileWriter.java From geopackage-java with MIT License | 5 votes |
/** * Get the length of the bounding box * * @param boundingBox * @return length */ private static double getLength(BoundingBox boundingBox) { double width = boundingBox.getMaxLongitude() - boundingBox.getMinLongitude(); double height = boundingBox.getMaxLatitude() - boundingBox.getMinLatitude(); double length = Math.min(width, height); return length; }
Example 7
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 5 votes |
/** * Get the zoom level of where the web mercator bounding box fits into the * complete world * * @param webMercatorBoundingBox * web mercator bounding box * @return zoom level */ public static int getZoomLevel(BoundingBox webMercatorBoundingBox) { double worldLength = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH * 2; double longitudeDistance = webMercatorBoundingBox.getMaxLongitude() - webMercatorBoundingBox.getMinLongitude(); double latitudeDistance = webMercatorBoundingBox.getMaxLatitude() - webMercatorBoundingBox.getMinLatitude(); if (longitudeDistance <= 0) { longitudeDistance = Double.MIN_VALUE; } if (latitudeDistance <= 0) { latitudeDistance = Double.MIN_VALUE; } int widthTiles = (int) (worldLength / longitudeDistance); int heightTiles = (int) (worldLength / latitudeDistance); int tilesPerSide = Math.min(widthTiles, heightTiles); tilesPerSide = Math.max(tilesPerSide, 1); int zoom = zoomFromTilesPerSide(tilesPerSide); return zoom; }
Example 8
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 5 votes |
/** * Get the bounding box of the tile grid in the tile width and height bounds * using the total bounding box with constant units * * @param totalBox * total bounding box * @param tileMatrixWidth * matrix width * @param tileMatrixHeight * matrix height * @param tileGrid * tile grid * @return bounding box * @since 1.2.0 */ public static BoundingBox getBoundingBox(BoundingBox totalBox, long tileMatrixWidth, long tileMatrixHeight, TileGrid tileGrid) { // Get the tile width double matrixMinX = totalBox.getMinLongitude(); double matrixMaxX = totalBox.getMaxLongitude(); double matrixWidth = matrixMaxX - matrixMinX; double tileWidth = matrixWidth / tileMatrixWidth; // Find the longitude range double minLon = matrixMinX + (tileWidth * tileGrid.getMinX()); double maxLon = matrixMinX + (tileWidth * (tileGrid.getMaxX() + 1)); // Get the tile height double matrixMinY = totalBox.getMinLatitude(); double matrixMaxY = totalBox.getMaxLatitude(); double matrixHeight = matrixMaxY - matrixMinY; double tileHeight = matrixHeight / tileMatrixHeight; // Find the latitude range double maxLat = matrixMaxY - (tileHeight * tileGrid.getMinY()); double minLat = matrixMaxY - (tileHeight * (tileGrid.getMaxY() + 1)); BoundingBox boundingBox = new BoundingBox(minLon, minLat, maxLon, maxLat); return boundingBox; }
Example 9
Source File: GoogleMapShape.java From geopackage-android-map with MIT License | 5 votes |
/** * Expand the bounding box by the LatLng * * @param boundingBox bounding box * @param latLng lat lng */ private void expandBoundingBox(BoundingBox boundingBox, LatLng latLng) { double latitude = latLng.latitude; double longitude = latLng.longitude; if (boundingBox.getMinLongitude() <= 3 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && boundingBox.getMaxLongitude() >= 3 * -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) { if (longitude < boundingBox.getMinLongitude()) { if (boundingBox.getMinLongitude() - longitude > (longitude + (2 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)) - boundingBox.getMaxLongitude()) { longitude += (2 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH); } } else if (longitude > boundingBox.getMaxLongitude()) { if (longitude - boundingBox.getMaxLongitude() > boundingBox.getMinLongitude() - (longitude - (2 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH))) { longitude -= (2 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH); } } } if (latitude < boundingBox.getMinLatitude()) { boundingBox.setMinLatitude(latitude); } if (latitude > boundingBox.getMaxLatitude()) { boundingBox.setMaxLatitude(latitude); } if (longitude < boundingBox.getMinLongitude()) { boundingBox.setMinLongitude(longitude); } if (longitude > boundingBox.getMaxLongitude()) { boundingBox.setMaxLongitude(longitude); } }
Example 10
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 5 votes |
/** * Get the Y pixel for where the latitude fits into the bounding box * * @param height * height * @param boundingBox * bounding box * @param latitude * latitude * @return y pixel */ public static float getYPixel(long height, BoundingBox boundingBox, double latitude) { double boxHeight = boundingBox.getMaxLatitude() - boundingBox.getMinLatitude(); double offset = boundingBox.getMaxLatitude() - latitude; double percentage = offset / boxHeight; float pixel = (float) (percentage * height); return pixel; }
Example 11
Source File: CoverageDataCore.java From geopackage-core-java with MIT License | 5 votes |
/** * Pad the bounding box with extra space for the overlapping pixels * * @param tileMatrix * tile matrix * @param boundingBox * bounding box * @param overlap * overlapping pixels * @return padded bounding box */ protected BoundingBox padBoundingBox(TileMatrix tileMatrix, BoundingBox boundingBox, int overlap) { double lonPixelPadding = tileMatrix.getPixelXSize() * overlap; double latPixelPadding = tileMatrix.getPixelYSize() * overlap; BoundingBox paddedBoundingBox = new BoundingBox( boundingBox.getMinLongitude() - lonPixelPadding, boundingBox.getMinLatitude() - latPixelPadding, boundingBox.getMaxLongitude() + lonPixelPadding, boundingBox.getMaxLatitude() + latPixelPadding); return paddedBoundingBox; }
Example 12
Source File: TileDao.java From geopackage-android with MIT License | 5 votes |
/** * Determine if the tiles are in the XYZ tile coordinate format * * @return true if XYZ tile format * @since 3.5.0 */ public boolean isXYZTiles() { // Convert the bounding box to wgs84 BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); BoundingBox wgs84BoundingBox = boundingBox.transform( projection.getTransformation( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)); boolean xyzTiles = false; // Verify the bounds are the entire world if (wgs84BoundingBox.getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE && wgs84BoundingBox.getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE && wgs84BoundingBox.getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && wgs84BoundingBox.getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) { xyzTiles = true; // Verify each tile matrix is the correct width and height for (TileMatrix tileMatrix : tileMatrices) { long zoomLevel = tileMatrix.getZoomLevel(); long tilesPerSide = TileBoundingBoxUtils .tilesPerSide((int) zoomLevel); if (tileMatrix.getMatrixWidth() != tilesPerSide || tileMatrix.getMatrixHeight() != tilesPerSide) { xyzTiles = false; break; } } } return xyzTiles; }
Example 13
Source File: CoverageData.java From geopackage-android with MIT License | 5 votes |
/** * Get the tile matrix for the zoom level as defined by the area of the * request * * @param request coverage data request * @return tile matrix or null */ private TileMatrix getTileMatrix(CoverageDataRequest request) { TileMatrix tileMatrix = null; // Check if the request overlaps coverage data bounding box if (request.overlap(coverageBoundingBox) != null) { // Get the tile distance BoundingBox projectedBoundingBox = request .getProjectedBoundingBox(); double distanceWidth = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); double distanceHeight = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); // Get the zoom level to request based upon the tile size Long zoomLevel = tileDao.getClosestZoomLevel(distanceWidth, distanceHeight); // If there is a matching zoom level if (zoomLevel != null) { tileMatrix = tileDao.getTileMatrix(zoomLevel); } } return tileMatrix; }
Example 14
Source File: CoverageDataCore.java From geopackage-core-java with MIT License | 4 votes |
/** * Reproject the coverage data to the requested projection * * @param values * coverage data values * @param requestedCoverageWidth * requested coverage data width * @param requestedCoverageHeight * requested coverage data height * @param requestBoundingBox * request bounding box in the request projection * @param transformRequestToCoverage * transformation from request to coverage data * @param coverageBoundingBox * coverage data bounding box * @return projected coverage data */ protected Double[][] reprojectCoverageData(Double[][] values, int requestedCoverageWidth, int requestedCoverageHeight, BoundingBox requestBoundingBox, ProjectionTransform transformRequestToCoverage, BoundingBox coverageBoundingBox) { final double requestedWidthUnitsPerPixel = (requestBoundingBox .getMaxLongitude() - requestBoundingBox.getMinLongitude()) / requestedCoverageWidth; final double requestedHeightUnitsPerPixel = (requestBoundingBox .getMaxLatitude() - requestBoundingBox.getMinLatitude()) / requestedCoverageHeight; final double tilesDistanceWidth = coverageBoundingBox.getMaxLongitude() - coverageBoundingBox.getMinLongitude(); final double tilesDistanceHeight = coverageBoundingBox.getMaxLatitude() - coverageBoundingBox.getMinLatitude(); final int width = values[0].length; final int height = values.length; Double[][] projectedValues = new Double[requestedCoverageHeight][requestedCoverageWidth]; // Retrieve each coverage data value in the unprojected coverage data for (int y = 0; y < requestedCoverageHeight; y++) { for (int x = 0; x < requestedCoverageWidth; x++) { double longitude = requestBoundingBox.getMinLongitude() + (x * requestedWidthUnitsPerPixel); double latitude = requestBoundingBox.getMaxLatitude() - (y * requestedHeightUnitsPerPixel); ProjCoordinate fromCoord = new ProjCoordinate(longitude, latitude); ProjCoordinate toCoord = transformRequestToCoverage .transform(fromCoord); double projectedLongitude = toCoord.x; double projectedLatitude = toCoord.y; int xPixel = (int) Math .round(((projectedLongitude - coverageBoundingBox .getMinLongitude()) / tilesDistanceWidth) * width); int yPixel = (int) Math .round(((coverageBoundingBox.getMaxLatitude() - projectedLatitude) / tilesDistanceHeight) * height); xPixel = Math.max(0, xPixel); xPixel = Math.min(width - 1, xPixel); yPixel = Math.max(0, yPixel); yPixel = Math.min(height - 1, yPixel); Double coverageData = values[yPixel][xPixel]; projectedValues[y][x] = coverageData; } } return projectedValues; }
Example 15
Source File: CoverageDataTiffImportTest.java From geopackage-java with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataTiff .getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 16
Source File: CoverageDataPngImportTest.java From geopackage-java with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 17
Source File: CoverageDataPngImportTest.java From geopackage-android with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 18
Source File: TileCreator.java From geopackage-android with MIT License | 4 votes |
/** * Reproject the tile to the requested projection * * @param tile tile in the tile matrix projection * @param requestedTileWidth requested tile width * @param requestedTileHeight requested tile height * @param requestBoundingBox request bounding box in the request projection * @param transformRequestToTiles transformation from request to tiles * @param tilesBoundingBox request bounding box in the tile matrix projection * @return projected tile */ private Bitmap reprojectTile(Bitmap tile, int requestedTileWidth, int requestedTileHeight, BoundingBox requestBoundingBox, ProjectionTransform transformRequestToTiles, BoundingBox tilesBoundingBox) { final double requestedWidthUnitsPerPixel = (requestBoundingBox.getMaxLongitude() - requestBoundingBox.getMinLongitude()) / requestedTileWidth; final double requestedHeightUnitsPerPixel = (requestBoundingBox.getMaxLatitude() - requestBoundingBox.getMinLatitude()) / requestedTileHeight; final double tilesDistanceWidth = tilesBoundingBox.getMaxLongitude() - tilesBoundingBox.getMinLongitude(); final double tilesDistanceHeight = tilesBoundingBox.getMaxLatitude() - tilesBoundingBox.getMinLatitude(); final int width = tile.getWidth(); final int height = tile.getHeight(); // Tile pixels of the tile matrix tiles int[] pixels = new int[width * height]; tile.getPixels(pixels, 0, width, 0, 0, width, height); // Projected tile pixels to draw the reprojected tile int[] projectedPixels = new int[requestedTileWidth * requestedTileHeight]; // Retrieve each pixel in the new tile from the unprojected tile for (int y = 0; y < requestedTileHeight; y++) { for (int x = 0; x < requestedTileWidth; x++) { double longitude = requestBoundingBox.getMinLongitude() + (x * requestedWidthUnitsPerPixel); double latitude = requestBoundingBox.getMaxLatitude() - (y * requestedHeightUnitsPerPixel); ProjCoordinate fromCoord = new ProjCoordinate(longitude, latitude); ProjCoordinate toCoord = transformRequestToTiles.transform(fromCoord); double projectedLongitude = toCoord.x; double projectedLatitude = toCoord.y; int xPixel = (int) Math.round(((projectedLongitude - tilesBoundingBox.getMinLongitude()) / tilesDistanceWidth) * width); int yPixel = (int) Math.round(((tilesBoundingBox.getMaxLatitude() - projectedLatitude) / tilesDistanceHeight) * height); xPixel = Math.max(0, xPixel); xPixel = Math.min(width - 1, xPixel); yPixel = Math.max(0, yPixel); yPixel = Math.min(height - 1, yPixel); int color = pixels[(yPixel * width) + xPixel]; projectedPixels[(y * requestedTileWidth) + x] = color; } } // Draw the new tile bitmap Bitmap projectedTileBitmap = Bitmap.createBitmap(requestedTileWidth, requestedTileHeight, tile.getConfig()); projectedTileBitmap.setPixels(projectedPixels, 0, requestedTileWidth, 0, 0, requestedTileWidth, requestedTileHeight); return projectedTileBitmap; }
Example 19
Source File: TileCreator.java From geopackage-java with MIT License | 4 votes |
/** * Reproject the tile to the requested projection * * @param tile * tile in the tile matrix projection * @param requestedTileWidth * requested tile width * @param requestedTileHeight * requested tile height * @param requestBoundingBox * request bounding box in the request projection * @param transformRequestToTiles * transformation from request to tiles * @param tilesBoundingBox * request bounding box in the tile matrix projection * @return projected tile */ private BufferedImage reprojectTile(BufferedImage tile, int requestedTileWidth, int requestedTileHeight, BoundingBox requestBoundingBox, ProjectionTransform transformRequestToTiles, BoundingBox tilesBoundingBox) { final double requestedWidthUnitsPerPixel = (requestBoundingBox .getMaxLongitude() - requestBoundingBox.getMinLongitude()) / requestedTileWidth; final double requestedHeightUnitsPerPixel = (requestBoundingBox .getMaxLatitude() - requestBoundingBox.getMinLatitude()) / requestedTileHeight; final double tilesDistanceWidth = tilesBoundingBox.getMaxLongitude() - tilesBoundingBox.getMinLongitude(); final double tilesDistanceHeight = tilesBoundingBox.getMaxLatitude() - tilesBoundingBox.getMinLatitude(); final int width = tile.getWidth(); final int height = tile.getHeight(); // Tile pixels of the tile matrix tiles int[] pixels = new int[width * height]; tile.getRGB(0, 0, width, height, pixels, 0, width); // Projected tile pixels to draw the reprojected tile int[] projectedPixels = new int[requestedTileWidth * requestedTileHeight]; // Retrieve each pixel in the new tile from the unprojected tile for (int y = 0; y < requestedTileHeight; y++) { for (int x = 0; x < requestedTileWidth; x++) { double longitude = requestBoundingBox.getMinLongitude() + (x * requestedWidthUnitsPerPixel); double latitude = requestBoundingBox.getMaxLatitude() - (y * requestedHeightUnitsPerPixel); ProjCoordinate fromCoord = new ProjCoordinate(longitude, latitude); ProjCoordinate toCoord = transformRequestToTiles .transform(fromCoord); double projectedLongitude = toCoord.x; double projectedLatitude = toCoord.y; int xPixel = (int) Math .round(((projectedLongitude - tilesBoundingBox .getMinLongitude()) / tilesDistanceWidth) * width); int yPixel = (int) Math .round(((tilesBoundingBox.getMaxLatitude() - projectedLatitude) / tilesDistanceHeight) * height); xPixel = Math.max(0, xPixel); xPixel = Math.min(width - 1, xPixel); yPixel = Math.max(0, yPixel); yPixel = Math.min(height - 1, yPixel); int color = pixels[(yPixel * width) + xPixel]; projectedPixels[(y * requestedTileWidth) + x] = color; } } // Draw the new image BufferedImage projectedTileImage = new BufferedImage( requestedTileWidth, requestedTileHeight, tile.getType()); projectedTileImage.setRGB(0, 0, requestedTileWidth, requestedTileHeight, projectedPixels, 0, requestedTileWidth); return projectedTileImage; }
Example 20
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 3 votes |
/** * Get the latitude from the pixel location, bounding box, tile bounding box * (when different from bounding box), and image height * * @param height * height * @param boundingBox * bounding box * @param tileBoundingBox * tile bounding box * @param pixel * pixel * @return latitude * @since 3.2.0 */ public static double getLatitudeFromPixel(long height, BoundingBox boundingBox, BoundingBox tileBoundingBox, float pixel) { double boxHeight = tileBoundingBox.getMaxLatitude() - tileBoundingBox.getMinLatitude(); double percentage = pixel / height; double offset = percentage * boxHeight; double latitude = boundingBox.getMaxLatitude() - offset; return latitude; }