Java Code Examples for mil.nga.geopackage.tiles.user.TileRow#getTileDataImage()
The following examples show how to use
mil.nga.geopackage.tiles.user.TileRow#getTileDataImage() .
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: CoverageDataPng.java From geopackage-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public double getValue(GriddedTile griddedTile, TileRow tileRow, int x, int y) { BufferedImage image = null; try { image = tileRow.getTileDataImage(); } catch (IOException e) { throw new GeoPackageException( "Failed to get the Tile Row Data Image", e); } double value = getValue(griddedTile, image, x, y); return value; }
Example 2
Source File: CoverageDataPngImage.java From geopackage-java with MIT License | 5 votes |
/** * Constructor * * @param tileRow * tile row */ public CoverageDataPngImage(TileRow tileRow) { try { image = tileRow.getTileDataImage(); } catch (IOException e) { throw new GeoPackageException( "Failed to get the Tile Row Data Image", e); } raster = image.getRaster(); }
Example 3
Source File: TileCreator.java From geopackage-java with MIT License | 4 votes |
/** * Draw the tile from the tile results * * @param tileMatrix * @param tileResults * @param requestProjectedBoundingBox * @param tileWidth * @param tileHeight * @return tile bitmap */ private GeoPackageTile drawTile(TileMatrix tileMatrix, TileResultSet tileResults, BoundingBox requestProjectedBoundingBox, int tileWidth, int tileHeight) { // Draw the resulting bitmap with the matching tiles GeoPackageTile geoPackageTile = null; Graphics graphics = null; while (tileResults.moveToNext()) { // Get the next tile TileRow tileRow = tileResults.getRow(); BufferedImage tileDataImage; try { tileDataImage = tileRow.getTileDataImage(); } catch (IOException e) { throw new GeoPackageException( "Failed to read the tile row image data", e); } // Get the bounding box of the tile BoundingBox tileBoundingBox = TileBoundingBoxUtils.getBoundingBox( tileSetBoundingBox, tileMatrix, tileRow.getTileColumn(), tileRow.getTileRow()); // Get the bounding box where the requested image and // tile overlap BoundingBox overlap = requestProjectedBoundingBox .overlap(tileBoundingBox); // If the tile overlaps with the requested box if (overlap != null) { // Get the rectangle of the tile image to draw ImageRectangle src = TileBoundingBoxJavaUtils.getRectangle( tileMatrix.getTileWidth(), tileMatrix.getTileHeight(), tileBoundingBox, overlap); // Get the rectangle of where to draw the tile in // the resulting image ImageRectangle dest = TileBoundingBoxJavaUtils.getRectangle( tileWidth, tileHeight, requestProjectedBoundingBox, overlap); if (src.isValid() && dest.isValid()) { if (imageFormat != null) { // Create the bitmap first time through if (geoPackageTile == null) { BufferedImage bufferedImage = ImageUtils .createBufferedImage(tileWidth, tileHeight, imageFormat); graphics = bufferedImage.getGraphics(); geoPackageTile = new GeoPackageTile(tileWidth, tileHeight, bufferedImage); } // Draw the tile to the image graphics.drawImage(tileDataImage, dest.getLeft(), dest.getTop(), dest.getRight(), dest.getBottom(), src.getLeft(), src.getTop(), src.getRight(), src.getBottom(), null); } else { // Verify only one image was found and // it lines up perfectly if (geoPackageTile != null || !src.equals(dest)) { throw new GeoPackageException( "Raw image only supported when the images are aligned with the tile format requiring no combining and cropping"); } geoPackageTile = new GeoPackageTile(tileWidth, tileHeight, tileRow.getTileData()); } } } } // Check if the entire image is transparent if (geoPackageTile != null && geoPackageTile.getImage() != null && ImageUtils.isFullyTransparent(geoPackageTile.getImage())) { geoPackageTile = null; } return geoPackageTile; }
Example 4
Source File: UrlTileGeneratorUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test generating tiles * * @param tileGenerator * @throws SQLException * @throws IOException */ private static void testGenerateTiles(TileGenerator tileGenerator) throws SQLException, IOException { GeoPackage geoPackage = tileGenerator.getGeoPackage(); String tableName = tileGenerator.getTableName(); int minZoom = tileGenerator.getMinZoom(); int maxZoom = tileGenerator.getMaxZoom(); BoundingBox webMercatorBoundingBox = tileGenerator.getBoundingBox(); TestGeoPackageProgress progress = new TestGeoPackageProgress(); tileGenerator.setProgress(progress); int count = tileGenerator.generateTiles(); long expected = expectedTiles(webMercatorBoundingBox, minZoom, maxZoom); TestCase.assertEquals(expected, count); TestCase.assertEquals(expected, progress.getProgress()); TileDao tileDao = geoPackage.getTileDao(tableName); TestCase.assertEquals(expected, tileDao.count()); TestCase.assertEquals(minZoom, tileDao.getMinZoom()); TestCase.assertEquals(maxZoom, tileDao.getMaxZoom()); BoundingBox tileMatrixSetBoundingBox = tileDao.getBoundingBox(); for (int zoom = minZoom; zoom <= maxZoom; zoom++) { TileGrid expectedTileGrid = TileBoundingBoxUtils.getTileGrid( webMercatorBoundingBox, zoom); BoundingBox expectedBoundingBox = TileBoundingBoxUtils .getWebMercatorBoundingBox(expectedTileGrid, zoom); BoundingBox zoomBoundingBox = tileDao.getBoundingBox(zoom); TestCase.assertEquals(expectedBoundingBox.getMinLongitude(), zoomBoundingBox.getMinLongitude(), .000001); TestCase.assertEquals(expectedBoundingBox.getMaxLongitude(), zoomBoundingBox.getMaxLongitude(), .000001); TestCase.assertEquals(expectedBoundingBox.getMinLatitude(), zoomBoundingBox.getMinLatitude(), .000001); TestCase.assertEquals(expectedBoundingBox.getMaxLatitude(), zoomBoundingBox.getMaxLatitude(), .000001); long expectedZoomTiles = expectedTiles(webMercatorBoundingBox, zoom); TestCase.assertEquals(expectedZoomTiles, tileDao.count(zoom)); TileMatrix tileMatrix = tileDao.getTileMatrix(zoom); TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( tileMatrixSetBoundingBox, tileMatrix.getMatrixWidth(), tileMatrix.getMatrixHeight(), zoomBoundingBox); TestCase.assertTrue(tileGrid.getMinX() >= 0); TestCase.assertTrue(tileGrid.getMaxX() < tileMatrix .getMatrixWidth()); TestCase.assertTrue(tileGrid.getMinY() >= 0); TestCase.assertTrue(tileGrid.getMaxY() < tileMatrix .getMatrixHeight()); TileResultSet resultSet = tileDao.queryForTile(zoom); TestCase.assertEquals(expectedZoomTiles, resultSet.getCount()); int resultCount = 0; while (resultSet.moveToNext()) { TileRow tileRow = resultSet.getRow(); resultCount++; byte[] tileData = tileRow.getTileData(); TestCase.assertNotNull(tileData); BufferedImage image = tileRow.getTileDataImage(); TestCase.assertNotNull(image); TestCase.assertEquals(tileMatrix.getTileWidth(), image.getWidth()); TestCase.assertEquals(tileMatrix.getTileHeight(), image.getHeight()); } TestCase.assertEquals(expectedZoomTiles, resultCount); } }