Java Code Examples for mil.nga.geopackage.tiles.matrix.TileMatrix#getTileWidth()
The following examples show how to use
mil.nga.geopackage.tiles.matrix.TileMatrix#getTileWidth() .
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: XYZGeoPackageTileRetriever.java From geopackage-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public GeoPackageTile getTile(int x, int y, int zoom) { GeoPackageTile tile = null; TileRow tileRow = retrieveTileRow(x, y, zoom); if (tileRow != null) { TileMatrix tileMatrix = tileDao.getTileMatrix(zoom); int tileWidth = (int) tileMatrix.getTileWidth(); int tileHeight = (int) tileMatrix.getTileHeight(); tile = new GeoPackageTile(tileWidth, tileHeight, tileRow.getTileData()); } return tile; }
Example 2
Source File: TileDaoUtils.java From geopackage-core-java with MIT License | 6 votes |
/** * Adjust the tile matrix lengths if needed. Check if the tile matrix width * and height need to expand to account for pixel * number of pixels fitting * into the tile matrix lengths * * @param tileMatrixSet * tile matrix set * @param tileMatrices * tile matrices */ public static void adjustTileMatrixLengths(TileMatrixSet tileMatrixSet, List<TileMatrix> tileMatrices) { double tileMatrixWidth = tileMatrixSet.getMaxX() - tileMatrixSet.getMinX(); double tileMatrixHeight = tileMatrixSet.getMaxY() - tileMatrixSet.getMinY(); for (TileMatrix tileMatrix : tileMatrices) { int tempMatrixWidth = (int) (tileMatrixWidth / (tileMatrix .getPixelXSize() * tileMatrix.getTileWidth())); int tempMatrixHeight = (int) (tileMatrixHeight / (tileMatrix .getPixelYSize() * tileMatrix.getTileHeight())); if (tempMatrixWidth > tileMatrix.getMatrixWidth()) { tileMatrix.setMatrixWidth(tempMatrixWidth); } if (tempMatrixHeight > tileMatrix.getMatrixHeight()) { tileMatrix.setMatrixHeight(tempMatrixHeight); } } }
Example 3
Source File: CoverageData.java From geopackage-android with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public CoverageDataResults getValues(CoverageDataRequest request, Integer width, Integer height) { CoverageDataResults coverageDataResults = null; // Transform to the projection of the coverage data tiles ProjectionTransform transformRequestToCoverage = null; BoundingBox requestProjectedBoundingBox = request.getBoundingBox(); if (!sameProjection) { transformRequestToCoverage = requestProjection .getTransformation(coverageProjection); requestProjectedBoundingBox = requestProjectedBoundingBox .transform(transformRequestToCoverage); } request.setProjectedBoundingBox(requestProjectedBoundingBox); // Determine how many overlapping pixels to store based upon the // algorithm int overlappingPixels; switch (algorithm) { case BICUBIC: overlappingPixels = 3; break; default: overlappingPixels = 1; } // Find the tile matrix and results CoverageDataTileMatrixResults results = getResults(request, requestProjectedBoundingBox, overlappingPixels); if (results != null) { TileMatrix tileMatrix = results.getTileMatrix(); TileCursor tileResults = results.getTileResults(); try { // Determine the requested coverage data dimensions, or use the // dimensions of a single tile matrix coverage data tile int requestedCoverageDataWidth = width != null ? width : (int) tileMatrix.getTileWidth(); int requestedCoverageDataHeight = height != null ? height : (int) tileMatrix.getTileHeight(); // Determine the size of the non projected coverage data results int tileWidth = requestedCoverageDataWidth; int tileHeight = requestedCoverageDataHeight; if (!sameProjection) { int projectedWidth = (int) Math .round((requestProjectedBoundingBox .getMaxLongitude() - requestProjectedBoundingBox .getMinLongitude()) / tileMatrix.getPixelXSize()); if (projectedWidth > 0) { tileWidth = projectedWidth; } int projectedHeight = (int) Math .round((requestProjectedBoundingBox .getMaxLatitude() - requestProjectedBoundingBox .getMinLatitude()) / tileMatrix.getPixelYSize()); if (projectedHeight > 0) { tileHeight = projectedHeight; } } // Retrieve the coverage data from the results Double[][] values = getValues(tileMatrix, tileResults, request, tileWidth, tileHeight, overlappingPixels); // Project the coverage data if needed if (values != null && !sameProjection && !request.isPoint()) { values = reprojectCoverageData(values, requestedCoverageDataWidth, requestedCoverageDataHeight, request.getBoundingBox(), transformRequestToCoverage, requestProjectedBoundingBox); } // Create the results if (values != null) { coverageDataResults = new CoverageDataResults(values, tileMatrix); } } finally { tileResults.close(); } } return coverageDataResults; }
Example 4
Source File: TileDao.java From geopackage-android with MIT License | 4 votes |
/** * Constructor * * @param database database name * @param db GeoPackage connection * @param tileMatrixSet tile matrix set * @param tileMatrices tile matrices * @param table tile table */ public TileDao(String database, GeoPackageConnection db, TileMatrixSet tileMatrixSet, List<TileMatrix> tileMatrices, TileTable table) { super(database, db, new TileConnection(db), table); this.tileDb = (TileConnection) getUserDb(); this.tileMatrixSet = tileMatrixSet; this.tileMatrices = tileMatrices; this.widths = new double[tileMatrices.size()]; this.heights = new double[tileMatrices.size()]; projection = tileMatrixSet.getProjection(); // Set the min and max zoom levels if (!tileMatrices.isEmpty()) { minZoom = tileMatrices.get(0).getZoomLevel(); maxZoom = tileMatrices.get(tileMatrices.size() - 1).getZoomLevel(); } else { minZoom = 0; maxZoom = 0; } // Populate the zoom level to tile matrix and the sorted tile widths and // heights for (int i = 0; i < tileMatrices.size(); i++) { TileMatrix tileMatrix = tileMatrices.get(i); zoomLevelToTileMatrix.put(tileMatrix.getZoomLevel(), tileMatrix); widths[tileMatrices.size() - i - 1] = tileMatrix.getPixelXSize() * tileMatrix.getTileWidth(); heights[tileMatrices.size() - i - 1] = tileMatrix.getPixelYSize() * tileMatrix.getTileHeight(); } if (tileMatrixSet.getContents() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + Contents.class.getSimpleName()); } if (tileMatrixSet.getSrs() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + SpatialReferenceSystem.class.getSimpleName()); } }
Example 5
Source File: TileCreator.java From geopackage-android with MIT License | 4 votes |
/** * Get the tile from the request bounding box in the request projection * * @param requestBoundingBox request bounding box in the request projection * @return tile */ 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); TileCursor 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 Bitmap tileBitmap = drawTile(tileMatrix, tileResults, requestProjectedBoundingBox, tileWidth, tileHeight); // Create the tile if (tileBitmap != null) { // Project the tile if needed if (!sameProjection) { Bitmap reprojectTile = reprojectTile(tileBitmap, requestedTileWidth, requestedTileHeight, requestBoundingBox, transformRequestToTiles, tilesBoundingBox); tileBitmap.recycle(); tileBitmap = reprojectTile; } try { byte[] tileData = BitmapConverter.toBytes( tileBitmap, COMPRESS_FORMAT); tileBitmap.recycle(); tile = new GeoPackageTile(requestedTileWidth, requestedTileHeight, tileData); } catch (IOException e) { Log.e(TileCreator.class.getSimpleName(), "Failed to create tile. min lat: " + requestBoundingBox.getMinLatitude() + ", max lat: " + requestBoundingBox.getMaxLatitude() + ", min lon: " + requestBoundingBox.getMinLongitude() + ", max lon: " + requestBoundingBox.getMaxLongitude(), e); } } } } finally { tileResults.close(); } } } return tile; }
Example 6
Source File: CoverageDataTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test the pixel encoding location * * @param geoPackage GeoPackage * @param allowNulls allow nulls * @throws Exception */ public static void testPixelEncoding(GeoPackage geoPackage, boolean allowNulls) throws Exception { List<String> coverageDataTables = CoverageData.getTables(geoPackage); TestCase.assertFalse(coverageDataTables.isEmpty()); TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); TestCase.assertTrue(tileMatrixSetDao.isTableExists()); TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TestCase.assertTrue(tileMatrixDao.isTableExists()); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = tileMatrixSetDao .queryForId(coverageTable); TileDao tileDao = geoPackage.getTileDao(tileMatrixSet); CoverageData<?> coverageData = CoverageData.getCoverageData( geoPackage, tileDao); GriddedCoverage griddedCoverage = coverageData.getGriddedCoverage(); GriddedCoverageEncodingType encoding = griddedCoverage .getGridCellEncodingType(); TileCursor tileCursor = tileDao.queryForTile(tileDao .getMaxZoom()); TestCase.assertNotNull(tileCursor); try { TestCase.assertTrue(tileCursor.getCount() > 0); while (tileCursor.moveToNext()) { TileRow tileRow = tileCursor.getRow(); TileMatrix tileMatrix = tileDao.getTileMatrix(tileRow .getZoomLevel()); TestCase.assertNotNull(tileMatrix); GriddedTile griddedTile = coverageData.getGriddedTile(tileRow .getId()); TestCase.assertNotNull(griddedTile); byte[] tileData = tileRow.getTileData(); TestCase.assertNotNull(tileData); BoundingBox boundingBox = TileBoundingBoxUtils.getBoundingBox( tileMatrixSet.getBoundingBox(), tileMatrix, tileRow.getTileColumn(), tileRow.getTileRow()); int tileHeight = (int) tileMatrix.getTileHeight(); int tileWidth = (int) tileMatrix.getTileWidth(); int heightChunk = Math.max(tileHeight / 10, 1); int widthChunk = Math.max(tileWidth / 10, 1); for (int y = 0; y < tileHeight; y = Math.min(y + heightChunk, y == tileHeight - 1 ? tileHeight : tileHeight - 1)) { for (int x = 0; x < tileWidth; x = Math.min(x + widthChunk, x == tileWidth - 1 ? tileWidth : tileWidth - 1)) { Double pixelValue = coverageData.getValue(griddedTile, tileData, x, y); double pixelLongitude = boundingBox.getMinLongitude() + (x * tileMatrix.getPixelXSize()); double pixelLatitude = boundingBox.getMaxLatitude() - (y * tileMatrix.getPixelYSize()); switch (encoding) { case CENTER: case AREA: pixelLongitude += (tileMatrix.getPixelXSize() / 2.0); pixelLatitude -= (tileMatrix.getPixelYSize() / 2.0); break; case CORNER: pixelLatitude -= tileMatrix.getPixelYSize(); break; } Double value = coverageData.getValue(pixelLatitude, pixelLongitude); if (!allowNulls || pixelValue != null) { TestCase.assertEquals("x: " + x + ", y: " + y + ", encoding: " + encoding, pixelValue, value); } } } break; } } finally { tileCursor.close(); } } }
Example 7
Source File: CoverageData.java From geopackage-java with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public CoverageDataResults getValues(CoverageDataRequest request, Integer width, Integer height) { CoverageDataResults coverageDataResults = null; // Transform to the projection of the coverage data tiles ProjectionTransform transformRequestToCoverage = null; BoundingBox requestProjectedBoundingBox = request.getBoundingBox(); if (!sameProjection) { transformRequestToCoverage = requestProjection .getTransformation(coverageProjection); requestProjectedBoundingBox = requestProjectedBoundingBox .transform(transformRequestToCoverage); } request.setProjectedBoundingBox(requestProjectedBoundingBox); // Determine how many overlapping pixels to store based upon the // algorithm int overlappingPixels; switch (algorithm) { case BICUBIC: overlappingPixels = 3; break; default: overlappingPixels = 1; } // Find the tile matrix and results CoverageDataTileMatrixResults results = getResults(request, requestProjectedBoundingBox, overlappingPixels); if (results != null) { TileMatrix tileMatrix = results.getTileMatrix(); TileResultSet tileResults = results.getTileResults(); try { // Determine the requested coverage data dimensions, or use the // dimensions of a single tile matrix coverage data tile int requestedCoverageDataWidth = width != null ? width : (int) tileMatrix.getTileWidth(); int requestedCoverageDataHeight = height != null ? height : (int) tileMatrix.getTileHeight(); // Determine the size of the non projected coverage data results int tileWidth = requestedCoverageDataWidth; int tileHeight = requestedCoverageDataHeight; if (!sameProjection) { int projectedWidth = (int) Math .round((requestProjectedBoundingBox .getMaxLongitude() - requestProjectedBoundingBox .getMinLongitude()) / tileMatrix.getPixelXSize()); if (projectedWidth > 0) { tileWidth = projectedWidth; } int projectedHeight = (int) Math .round((requestProjectedBoundingBox .getMaxLatitude() - requestProjectedBoundingBox .getMinLatitude()) / tileMatrix.getPixelYSize()); if (projectedHeight > 0) { tileHeight = projectedHeight; } } // Retrieve the coverage data from the results Double[][] values = getValues(tileMatrix, tileResults, request, tileWidth, tileHeight, overlappingPixels); // Project the coverage data if needed if (values != null && !sameProjection && !request.isPoint()) { values = reprojectCoverageData(values, requestedCoverageDataWidth, requestedCoverageDataHeight, request.getBoundingBox(), transformRequestToCoverage, requestProjectedBoundingBox); } // Create the results if (values != null) { coverageDataResults = new CoverageDataResults(values, tileMatrix); } } finally { tileResults.close(); } } return coverageDataResults; }
Example 8
Source File: TileCreator.java From geopackage-java with MIT License | 4 votes |
/** * Get the tile from the request bounding box in the request projection * * @param requestBoundingBox * request bounding box in the request projection * @return image */ 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; }
Example 9
Source File: TileDao.java From geopackage-java with MIT License | 4 votes |
/** * Constructor * * @param database * database * @param db * GeoPackage connection * @param tileMatrixSet * tile matrix set * @param tileMatrices * tile matrices * @param table * tile table */ public TileDao(String database, GeoPackageConnection db, TileMatrixSet tileMatrixSet, List<TileMatrix> tileMatrices, TileTable table) { super(database, db, new TileConnection(db), table); this.tileDb = (TileConnection) getUserDb(); this.tileMatrixSet = tileMatrixSet; this.tileMatrices = tileMatrices; this.widths = new double[tileMatrices.size()]; this.heights = new double[tileMatrices.size()]; projection = tileMatrixSet.getProjection(); // Set the min and max zoom levels if (!tileMatrices.isEmpty()) { minZoom = tileMatrices.get(0).getZoomLevel(); maxZoom = tileMatrices.get(tileMatrices.size() - 1).getZoomLevel(); } else { minZoom = 0; maxZoom = 0; } // Populate the zoom level to tile matrix and the sorted tile widths and // heights for (int i = 0; i < tileMatrices.size(); i++) { TileMatrix tileMatrix = tileMatrices.get(i); zoomLevelToTileMatrix.put(tileMatrix.getZoomLevel(), tileMatrix); widths[tileMatrices.size() - i - 1] = tileMatrix.getPixelXSize() * tileMatrix.getTileWidth(); heights[tileMatrices.size() - i - 1] = tileMatrix.getPixelYSize() * tileMatrix.getTileHeight(); } if (tileMatrixSet.getContents() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + Contents.class.getSimpleName()); } if (tileMatrixSet.getSrs() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + SpatialReferenceSystem.class.getSimpleName()); } }
Example 10
Source File: TileUtils.java From geopackage-android with MIT License | 2 votes |
/** * Test getZoomLevel * * @param geoPackage GeoPackage * @throws SQLException upon error */ public static void testGetZoomLevel(GeoPackage geoPackage) throws SQLException { TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); if (tileMatrixSetDao.isTableExists()) { List<TileMatrixSet> results = tileMatrixSetDao.queryForAll(); for (TileMatrixSet tileMatrixSet : results) { TileDao dao = geoPackage.getTileDao(tileMatrixSet); List<TileMatrix> tileMatrices = dao.getTileMatrices(); for (TileMatrix tileMatrix : tileMatrices) { double width = tileMatrix.getPixelXSize() * tileMatrix.getTileWidth(); double height = tileMatrix.getPixelYSize() * tileMatrix.getTileHeight(); long zoomLevel = dao.getZoomLevel(width); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width, height); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width + 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width + 1, height + 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width - 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width - 1, height - 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); } } } }
Example 11
Source File: TileUtils.java From geopackage-java with MIT License | 2 votes |
/** * Test getZoomLevel * * @param geoPackage * GeoPackage * @throws SQLException * upon error */ public static void testGetZoomLevel(GeoPackage geoPackage) throws SQLException { TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); if (tileMatrixSetDao.isTableExists()) { List<TileMatrixSet> results = tileMatrixSetDao.queryForAll(); for (TileMatrixSet tileMatrixSet : results) { TileDao dao = geoPackage.getTileDao(tileMatrixSet); List<TileMatrix> tileMatrices = dao.getTileMatrices(); for (TileMatrix tileMatrix : tileMatrices) { double width = tileMatrix.getPixelXSize() * tileMatrix.getTileWidth(); double height = tileMatrix.getPixelYSize() * tileMatrix.getTileHeight(); long zoomLevel = dao.getZoomLevel(width); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width, height); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width + 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width + 1, height + 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width - 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); zoomLevel = dao.getZoomLevel(width - 1, height - 1); TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel); } } } }