Java Code Examples for mil.nga.geopackage.tiles.user.TileRow#getTileData()
The following examples show how to use
mil.nga.geopackage.tiles.user.TileRow#getTileData() .
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: CoverageDataPng.java From geopackage-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public double getValue(GriddedTile griddedTile, TileRow tileRow, int x, int y) { byte[] imageBytes = tileRow.getTileData(); double value = getValue(griddedTile, imageBytes, x, y); return value; }
Example 3
Source File: CoverageDataTiffImage.java From geopackage-android with MIT License | 5 votes |
/** * Constructor, used for reading a TIFF * * @param tileRow tile row */ public CoverageDataTiffImage(TileRow tileRow) { imageBytes = tileRow.getTileData(); TIFFImage tiffImage = TiffReader.readTiff(imageBytes); directory = tiffImage.getFileDirectory(); CoverageDataTiff.validateImageType(directory); width = directory.getImageWidth().intValue(); height = directory.getImageHeight().intValue(); }
Example 4
Source File: CoverageDataPngImage.java From geopackage-android with MIT License | 5 votes |
/** * Constructor, used for reading a PNG * * @param tileRow tile row */ public CoverageDataPngImage(TileRow tileRow) { imageBytes = tileRow.getTileData(); reader = new PngReaderInt(new ByteArrayInputStream(imageBytes)); CoverageDataPng.validateImageType(reader); width = reader.imgInfo.cols; height = reader.imgInfo.rows; }
Example 5
Source File: CoverageDataTiff.java From geopackage-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public double getValue(GriddedTile griddedTile, TileRow tileRow, int x, int y) { byte[] imageBytes = tileRow.getTileData(); double value = getValue(griddedTile, imageBytes, x, y); return value; }
Example 6
Source File: CoverageDataTiffImage.java From geopackage-java with MIT License | 5 votes |
/** * Constructor, used for reading a TIFF * * @param tileRow * tile row */ public CoverageDataTiffImage(TileRow tileRow) { imageBytes = tileRow.getTileData(); TIFFImage tiffImage = TiffReader.readTiff(imageBytes); directory = tiffImage.getFileDirectory(); CoverageDataTiff.validateImageType(directory); width = directory.getImageWidth().intValue(); height = directory.getImageHeight().intValue(); }
Example 7
Source File: CoverageDataTiff.java From geopackage-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public double getValue(GriddedTile griddedTile, TileRow tileRow, int x, int y) { byte[] imageBytes = tileRow.getTileData(); double value = getValue(griddedTile, imageBytes, x, y); return value; }
Example 8
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 9
Source File: TileUtils.java From geopackage-android with MIT License | 4 votes |
/** * Validate a tile row * * @param dao * @param columns * @param tileRow * @param testBitmap */ private static void validateTileRow(TileDao dao, String[] columns, TileRow tileRow, boolean testBitmap) { TestCase.assertEquals(columns.length, tileRow.columnCount()); for (int i = 0; i < tileRow.columnCount(); i++) { TileColumn column = tileRow.getTable().getColumns().get(i); TestCase.assertEquals(i, column.getIndex()); TestCase.assertEquals(columns[i], tileRow.getColumnName(i)); TestCase.assertEquals(i, tileRow.getColumnIndex(columns[i])); int rowType = tileRow.getRowColumnType(i); Object value = tileRow.getValue(i); switch (rowType) { case Cursor.FIELD_TYPE_INTEGER: TestUtils.validateIntegerValue(value, column.getDataType()); break; case Cursor.FIELD_TYPE_FLOAT: TestUtils.validateFloatValue(value, column.getDataType()); break; case Cursor.FIELD_TYPE_STRING: TestCase.assertTrue(value instanceof String); break; case Cursor.FIELD_TYPE_BLOB: TestCase.assertTrue(value instanceof byte[]); break; case Cursor.FIELD_TYPE_NULL: TestCase.assertNull(value); break; } } TestCase.assertTrue(tileRow.getId() >= 0); TestCase.assertTrue(tileRow.getZoomLevel() >= 0); TestCase.assertTrue(tileRow.getTileColumn() >= 0); TestCase.assertTrue(tileRow.getTileRow() >= 0); byte[] tileData = tileRow.getTileData(); TestCase.assertNotNull(tileData); TestCase.assertTrue(tileData.length > 0); TileMatrix tileMatrix = dao.getTileMatrix(tileRow.getZoomLevel()); TestCase.assertNotNull(tileMatrix); if (testBitmap) { Bitmap bitmap = tileRow.getTileDataBitmap(); if (dao.getTileMatrixSet().getContents().getDataType() != ContentsDataType.GRIDDED_COVERAGE) { TestCase.assertNotNull(bitmap); TestCase.assertEquals(tileMatrix.getTileWidth(), bitmap.getWidth()); TestCase.assertEquals(tileMatrix.getTileHeight(), bitmap.getHeight()); } } }
Example 10
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 11
Source File: TileUtils.java From geopackage-java with MIT License | 4 votes |
/** * Validate a tile row * * @param dao * @param columns * @param tileRow */ private static void validateTileRow(TileDao dao, String[] columns, TileRow tileRow) { TestCase.assertEquals(columns.length, tileRow.columnCount()); for (int i = 0; i < tileRow.columnCount(); i++) { TileColumn column = tileRow.getTable().getColumns().get(i); TestCase.assertEquals(i, column.getIndex()); TestCase.assertEquals(columns[i], tileRow.getColumnName(i)); TestCase.assertEquals(i, tileRow.getColumnIndex(columns[i])); int rowType = tileRow.getRowColumnType(i); Object value = tileRow.getValue(i); switch (rowType) { case ResultUtils.FIELD_TYPE_INTEGER: TestUtils.validateIntegerValue(value, column.getDataType()); break; case ResultUtils.FIELD_TYPE_FLOAT: TestUtils.validateFloatValue(value, column.getDataType()); break; case ResultUtils.FIELD_TYPE_STRING: TestCase.assertTrue(value instanceof String); break; case ResultUtils.FIELD_TYPE_BLOB: TestCase.assertTrue(value instanceof byte[]); break; case ResultUtils.FIELD_TYPE_NULL: TestCase.assertNull(value); break; } } TestCase.assertTrue(tileRow.getId() >= 0); TestCase.assertTrue(tileRow.getZoomLevel() >= 0); TestCase.assertTrue(tileRow.getTileColumn() >= 0); TestCase.assertTrue(tileRow.getTileRow() >= 0); byte[] tileData = tileRow.getTileData(); TestCase.assertNotNull(tileData); TestCase.assertTrue(tileData.length > 0); TileMatrix tileMatrix = dao.getTileMatrix(tileRow.getZoomLevel()); TestCase.assertNotNull(tileMatrix); }
Example 12
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); } }