Search in sources :

Example 1 with TileMatrixSet

use of mil.nga.geopackage.tiles.matrixset.TileMatrixSet in project geopackage-android-map by ngageoint.

the class GeoPackageOverlayUtils method testOverlay.

/**
 * Test overlay
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testOverlay(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);
            GeoPackageOverlay overlay = new GeoPackageOverlay(dao);
            for (int zoom = 0; zoom <= 21; zoom++) {
                int tileLength = (int) Math.pow(2, zoom);
                int column = (int) (Math.random() * tileLength);
                int row = (int) (Math.random() * tileLength);
                for (int maxColumns = Math.min(tileLength, column + 2); column < maxColumns; column++) {
                    for (int maxRows = Math.min(tileLength, row + 2); row < maxRows; row++) {
                        Tile tile = overlay.getTile(column, row, zoom);
                        if (tile != null) {
                            TestCase.assertTrue(tile.height > 0);
                            TestCase.assertTrue(tile.width > 0);
                        }
                    }
                }
            }
        }
    }
}
Also used : TileMatrixSet(mil.nga.geopackage.tiles.matrixset.TileMatrixSet) Tile(com.google.android.gms.maps.model.Tile) TileMatrixSetDao(mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao) TileDao(mil.nga.geopackage.tiles.user.TileDao)

Example 2 with TileMatrixSet

use of mil.nga.geopackage.tiles.matrixset.TileMatrixSet in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpCreateTiles.

/**
 * Set up create for tiles test
 *
 * @param testContext
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(Context testContext, GeoPackage geoPackage) throws SQLException, IOException {
    // Get existing SRS objects
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);
    TestCase.assertNotNull(epsgSrs);
    // Create the Tile Matrix Set and Tile Matrix tables
    geoPackage.createTileMatrixSetTable();
    geoPackage.createTileMatrixTable();
    // Create new Contents
    ContentsDao contentsDao = geoPackage.getContentsDao();
    Contents contents = new Contents();
    contents.setTableName("test_tiles");
    contents.setDataType(ContentsDataType.TILES);
    contents.setIdentifier("test_tiles");
    // contents.setDescription("");
    // contents.setLastChange(new Date());
    contents.setMinX(-180.0);
    contents.setMinY(-90.0);
    contents.setMaxX(180.0);
    contents.setMaxY(90.0);
    contents.setSrs(epsgSrs);
    // Create the user tile table
    TileTable tileTable = TestUtils.buildTileTable(contents.getTableName());
    geoPackage.createTileTable(tileTable);
    // Create the contents
    contentsDao.create(contents);
    // Create new Tile Matrix Set
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TileMatrixSet tileMatrixSet = new TileMatrixSet();
    tileMatrixSet.setContents(contents);
    tileMatrixSet.setSrs(contents.getSrs());
    tileMatrixSet.setMinX(contents.getMinX());
    tileMatrixSet.setMinY(contents.getMinY());
    tileMatrixSet.setMaxX(contents.getMaxX());
    tileMatrixSet.setMaxY(contents.getMaxY());
    tileMatrixSetDao.create(tileMatrixSet);
    // Create new Tile Matrix rows
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    int matrixWidthAndHeight = 2;
    double pixelXSize = 69237.2;
    double pixelYSize = 68412.1;
    // Read the asset tile to bytes and convert to bitmap
    byte[] assetTileData = TestUtils.getAssetFileBytes(testContext, TestConstants.TILE_FILE_NAME);
    Bitmap bitmap = BitmapConverter.toBitmap(assetTileData);
    // Get the width and height of the bitmap
    final int tileWidth = bitmap.getWidth();
    final int tileHeight = bitmap.getHeight();
    // Compress the bitmap back to bytes and use those for the test
    byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat.valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase()));
    for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) {
        TileMatrix tileMatrix = new TileMatrix();
        tileMatrix.setContents(contents);
        tileMatrix.setZoomLevel(zoom);
        tileMatrix.setMatrixWidth(matrixWidthAndHeight);
        tileMatrix.setMatrixHeight(matrixWidthAndHeight);
        tileMatrix.setTileWidth(tileWidth);
        tileMatrix.setTileHeight(tileHeight);
        tileMatrix.setPixelXSize(pixelXSize);
        tileMatrix.setPixelYSize(pixelYSize);
        tileMatrixDao.create(tileMatrix);
        matrixWidthAndHeight *= 2;
        pixelXSize /= 2.0;
        pixelYSize /= 2.0;
        // Populate the tile table with rows
        TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData);
    }
}
Also used : TileMatrixSet(mil.nga.geopackage.tiles.matrixset.TileMatrixSet) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) TileMatrixDao(mil.nga.geopackage.tiles.matrix.TileMatrixDao) Bitmap(android.graphics.Bitmap) Contents(mil.nga.geopackage.contents.Contents) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) TileTable(mil.nga.geopackage.tiles.user.TileTable) TileMatrixSetDao(mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao) ContentsDao(mil.nga.geopackage.contents.ContentsDao) TileMatrix(mil.nga.geopackage.tiles.matrix.TileMatrix)

Aggregations

TileMatrixSet (mil.nga.geopackage.tiles.matrixset.TileMatrixSet)2 TileMatrixSetDao (mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao)2 Bitmap (android.graphics.Bitmap)1 Tile (com.google.android.gms.maps.model.Tile)1 Contents (mil.nga.geopackage.contents.Contents)1 ContentsDao (mil.nga.geopackage.contents.ContentsDao)1 SpatialReferenceSystem (mil.nga.geopackage.srs.SpatialReferenceSystem)1 SpatialReferenceSystemDao (mil.nga.geopackage.srs.SpatialReferenceSystemDao)1 TileMatrix (mil.nga.geopackage.tiles.matrix.TileMatrix)1 TileMatrixDao (mil.nga.geopackage.tiles.matrix.TileMatrixDao)1 TileDao (mil.nga.geopackage.tiles.user.TileDao)1 TileTable (mil.nga.geopackage.tiles.user.TileTable)1