Java Code Examples for mil.nga.geopackage.tiles.TileBoundingBoxUtils#getBoundingBox()

The following examples show how to use mil.nga.geopackage.tiles.TileBoundingBoxUtils#getBoundingBox() . 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: TileDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the bounding box of tiles
 *
 * @param zoomLevel zoom level
 * @return bounding box of zoom level, or null if no tiles
 * @since 1.1.1
 */
public BoundingBox getBoundingBox(long zoomLevel) {
    BoundingBox boundingBox = null;
    TileMatrix tileMatrix = getTileMatrix(zoomLevel);
    if (tileMatrix != null) {
        TileGrid tileGrid = queryForTileGrid(zoomLevel);
        if (tileGrid != null) {
            BoundingBox matrixSetBoundingBox = getBoundingBox();
            boundingBox = TileBoundingBoxUtils.getBoundingBox(
                    matrixSetBoundingBox, tileMatrix, tileGrid);
        }

    }
    return boundingBox;
}
 
Example 2
Source File: TileDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the bounding box of tiles
 * 
 * @param zoomLevel
 *            zoom level
 * @return bounding box of zoom level, or null if no tiles
 * @since 1.1.1
 */
public BoundingBox getBoundingBox(long zoomLevel) {
	BoundingBox boundingBox = null;
	TileMatrix tileMatrix = getTileMatrix(zoomLevel);
	if (tileMatrix != null) {
		TileGrid tileGrid = queryForTileGrid(zoomLevel);
		if (tileGrid != null) {
			BoundingBox matrixSetBoundingBox = getBoundingBox();
			boundingBox = TileBoundingBoxUtils.getBoundingBox(
					matrixSetBoundingBox, tileMatrix, tileGrid);
		}

	}
	return boundingBox;
}
 
Example 3
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();
        }
    }

}