Java Code Examples for mil.nga.geopackage.tiles.user.TileDao#getTileMatrix()

The following examples show how to use mil.nga.geopackage.tiles.user.TileDao#getTileMatrix() . 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: GeoPackageTextOutput.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Build text from a tile table
 * 
 * @param table
 *            tile table
 * @return text
 */
public String tileTable(String table) {

	StringBuilder output = new StringBuilder();
	TileDao tileDao = geoPackage.getTileDao(table);
	output.append("Table Name: " + tileDao.getTableName());
	long minZoom = tileDao.getMinZoom();
	long maxZoom = tileDao.getMaxZoom();
	output.append("\nMin Zoom: " + minZoom);
	output.append("\nMax Zoom: " + maxZoom);
	output.append("\nTiles: " + tileDao.count());

	TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet();

	output.append("\n\nContents\n\n")
			.append(textOutput(tileMatrixSet.getContents()));

	output.append("\n\nTile Matrix Set\n\n")
			.append(textOutput(tileMatrixSet));

	output.append("\n\n Tile Matrices");

	for (long zoom = minZoom; zoom <= maxZoom; zoom++) {
		TileMatrix tileMatrix = tileDao.getTileMatrix(zoom);
		if (tileMatrix != null) {
			output.append("\n\n").append(textOutput(tileMatrix));
			output.append("\n\tTiles: " + tileDao.count(zoom));
			BoundingBox boundingBox = tileDao.getBoundingBox(zoom);
			output.append("\n\tTile Bounds: \n")
					.append(textOutput(boundingBox));
		}
	}

	return output.toString();
}
 
Example 2
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * 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 3
Source File: TileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * 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 4
Source File: TileUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * 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 5
Source File: UrlTileGeneratorUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * 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);
	}

}