Java Code Examples for mil.nga.geopackage.tiles.user.TileTable

The following examples show how to use mil.nga.geopackage.tiles.user.TileTable. These examples are extracted from open source projects. 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 Project: geopackage-android   Source File: CoverageData.java    License: MIT License 6 votes vote down vote up
/**
 * Get the tile row results of coverage data tiles needed to create the
 * requested bounding box coverage data, sorted by row and then column
 *
 * @param projectedRequestBoundingBox bounding box projected to the coverage data
 * @param tileMatrix                  tile matrix
 * @return tile results or null
 */
private TileCursor retrieveSortedTileResults(
        BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) {

    TileCursor tileResults = null;

    if (tileMatrix != null) {

        // Get the tile grid
        TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
                coverageBoundingBox, tileMatrix.getMatrixWidth(),
                tileMatrix.getMatrixHeight(), projectedRequestBoundingBox);

        // Query for matching tiles in the tile grid
        tileResults = tileDao.queryByTileGrid(tileGrid,
                tileMatrix.getZoomLevel(), TileTable.COLUMN_TILE_ROW + ","
                        + TileTable.COLUMN_TILE_COLUMN);

    }

    return tileResults;
}
 
Example 2
Source Project: geopackage-android   Source File: WebPExtensionTest.java    License: MIT License 6 votes vote down vote up
/**
 * Test the WebP Extension creation
 */
@Test
public void testWebPExtension() throws Exception {

    WebPExtension webpExtension = new WebPExtension(geoPackage);

    String tableName = "table";

    Extensions extension = webpExtension.getOrCreate(tableName);
    assertNotNull(extension);
    assertTrue(webpExtension.has(tableName));

    assertEquals(extension.getExtensionName(), WebPExtension.EXTENSION_NAME);
    assertEquals(extension.getAuthor(),
            GeoPackageConstants.EXTENSION_AUTHOR);
    assertEquals(extension.getExtensionNameNoAuthor(), WebPExtension.NAME);
    assertEquals(extension.getTableName(), tableName);
    assertEquals(extension.getColumnName(), TileTable.COLUMN_TILE_DATA);
    assertEquals(extension.getScope(), ExtensionScopeType.READ_WRITE);
    assertEquals(extension.getDefinition(), WebPExtension.DEFINITION);

    GeoPackageExtensions.deleteTableExtensions(geoPackage, tableName);
    assertFalse(webpExtension.has(tableName));

}
 
Example 3
Source Project: geopackage-core-java   Source File: CoverageDataCore.java    License: MIT License 6 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @return extensions list
 */
public List<Extensions> getOrCreate() {

	// Create tables
	geoPackage.createGriddedCoverageTable();
	geoPackage.createGriddedTileTable();

	List<Extensions> extensionList = new ArrayList<>();

	Extensions coverage = getOrCreate(EXTENSION_NAME,
			GriddedCoverage.TABLE_NAME, null, EXTENSION_DEFINITION,
			ExtensionScopeType.READ_WRITE);
	Extensions tile = getOrCreate(EXTENSION_NAME, GriddedTile.TABLE_NAME,
			null, EXTENSION_DEFINITION, ExtensionScopeType.READ_WRITE);
	Extensions table = getOrCreate(EXTENSION_NAME,
			tileMatrixSet.getTableName(), TileTable.COLUMN_TILE_DATA,
			EXTENSION_DEFINITION, ExtensionScopeType.READ_WRITE);

	extensionList.add(coverage);
	extensionList.add(tile);
	extensionList.add(table);

	return extensionList;
}
 
Example 4
Source Project: geopackage-java   Source File: CoverageData.java    License: MIT License 6 votes vote down vote up
/**
 * Get the tile row results of coverage data tiles needed to create the
 * requested bounding box coverage data, sorted by row and then column
 *
 * @param projectedRequestBoundingBox
 *            bounding box projected to the coverage data
 * @param tileMatrix
 *            tile matrix
 * @return tile results or null
 */
private TileResultSet retrieveSortedTileResults(
		BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) {

	TileResultSet tileResults = null;

	if (tileMatrix != null) {

		// Get the tile grid
		TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
				coverageBoundingBox, tileMatrix.getMatrixWidth(),
				tileMatrix.getMatrixHeight(), projectedRequestBoundingBox);

		// Query for matching tiles in the tile grid
		tileResults = tileDao.queryByTileGrid(tileGrid,
				tileMatrix.getZoomLevel(), TileTable.COLUMN_TILE_ROW + ","
						+ TileTable.COLUMN_TILE_COLUMN);

	}

	return tileResults;
}
 
Example 5
Source Project: geopackage-java   Source File: WebPExtensionTest.java    License: MIT License 6 votes vote down vote up
/**
 * Test the WebP Extension creation
 */
@Test
public void testWebPExtension() throws Exception {

	WebPExtension webpExtension = new WebPExtension(geoPackage);

	String tableName = "table";

	Extensions extension = webpExtension.getOrCreate(tableName);
	assertNotNull(extension);
	assertTrue(webpExtension.has(tableName));

	assertEquals(extension.getExtensionName(), WebPExtension.EXTENSION_NAME);
	assertEquals(extension.getAuthor(),
			GeoPackageConstants.EXTENSION_AUTHOR);
	assertEquals(extension.getExtensionNameNoAuthor(), WebPExtension.NAME);
	assertEquals(extension.getTableName(), tableName);
	assertEquals(extension.getColumnName(), TileTable.COLUMN_TILE_DATA);
	assertEquals(extension.getScope(), ExtensionScopeType.READ_WRITE);
	assertEquals(extension.getDefinition(), WebPExtension.DEFINITION);

	GeoPackageExtensions.deleteTableExtensions(geoPackage, tableName);
	assertFalse(webpExtension.has(tableName));

}
 
Example 6
Source Project: geopackage-android   Source File: ZoomOtherExtensionTest.java    License: MIT License 5 votes vote down vote up
/**
 * Test the Zoom Other Extension creation
 */
@Test
public void testZoomOtherExtension() throws Exception {

    ZoomOtherExtension zoomOtherExtension = new ZoomOtherExtension(
            geoPackage);

    String tableName = "table";

    Extensions extension = zoomOtherExtension.getOrCreate(tableName);
    assertNotNull(extension);
    assertTrue(zoomOtherExtension.has(tableName));

    assertEquals(extension.getExtensionName(),
            ZoomOtherExtension.EXTENSION_NAME);
    assertEquals(extension.getAuthor(),
            GeoPackageConstants.EXTENSION_AUTHOR);
    assertEquals(extension.getExtensionNameNoAuthor(),
            ZoomOtherExtension.NAME);
    assertEquals(extension.getTableName(), tableName);
    assertEquals(extension.getColumnName(), TileTable.COLUMN_TILE_DATA);
    assertEquals(extension.getScope(), ExtensionScopeType.READ_WRITE);
    assertEquals(extension.getDefinition(), ZoomOtherExtension.DEFINITION);

    GeoPackageExtensions.deleteTableExtensions(geoPackage, tableName);
    assertFalse(zoomOtherExtension.has(tableName));

}
 
Example 7
Source Project: geopackage-core-java   Source File: WebPExtension.java    License: MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @param tableName
 *            table name
 * @return extension
 */
public Extensions getOrCreate(String tableName) {

	Extensions extension = getOrCreate(EXTENSION_NAME, tableName,
			TileTable.COLUMN_TILE_DATA, DEFINITION,
			ExtensionScopeType.READ_WRITE);

	return extension;
}
 
Example 8
Source Project: geopackage-core-java   Source File: WebPExtension.java    License: MIT License 5 votes vote down vote up
/**
 * Determine if the GeoPackage has the extension
 * 
 * @param tableName
 *            table name
 * @return true if has extension
 */
public boolean has(String tableName) {

	boolean exists = has(EXTENSION_NAME, tableName,
			TileTable.COLUMN_TILE_DATA);

	return exists;
}
 
Example 9
Source Project: geopackage-core-java   Source File: ZoomOtherExtension.java    License: MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @param tableName
 *            table name
 * @return extension
 */
public Extensions getOrCreate(String tableName) {

	Extensions extension = getOrCreate(EXTENSION_NAME, tableName,
			TileTable.COLUMN_TILE_DATA, DEFINITION,
			ExtensionScopeType.READ_WRITE);

	return extension;
}
 
Example 10
Source Project: geopackage-core-java   Source File: ZoomOtherExtension.java    License: MIT License 5 votes vote down vote up
/**
 * Determine if the GeoPackage has the extension
 * 
 * @param tableName
 *            table name
 * @return true if has extension
 */
public boolean has(String tableName) {

	boolean exists = has(EXTENSION_NAME, tableName,
			TileTable.COLUMN_TILE_DATA);

	return exists;
}
 
Example 11
Source Project: geopackage-core-java   Source File: CoverageDataCore.java    License: MIT License 5 votes vote down vote up
/**
 * Determine if the Tile Matrix Set has the extension
 * 
 * @return true if has extension
 */
public boolean has() {

	boolean exists = has(EXTENSION_NAME, tileMatrixSet.getTableName(),
			TileTable.COLUMN_TILE_DATA);

	return exists;
}
 
Example 12
Source Project: geopackage-java   Source File: ZoomOtherExtensionTest.java    License: MIT License 5 votes vote down vote up
/**
 * Test the Zoom Other Extension creation
 */
@Test
public void testZoomOtherExtension() throws Exception {

	ZoomOtherExtension zoomOtherExtension = new ZoomOtherExtension(
			geoPackage);

	String tableName = "table";

	Extensions extension = zoomOtherExtension.getOrCreate(tableName);
	assertNotNull(extension);
	assertTrue(zoomOtherExtension.has(tableName));

	assertEquals(extension.getExtensionName(),
			ZoomOtherExtension.EXTENSION_NAME);
	assertEquals(extension.getAuthor(),
			GeoPackageConstants.EXTENSION_AUTHOR);
	assertEquals(extension.getExtensionNameNoAuthor(),
			ZoomOtherExtension.NAME);
	assertEquals(extension.getTableName(), tableName);
	assertEquals(extension.getColumnName(), TileTable.COLUMN_TILE_DATA);
	assertEquals(extension.getScope(), ExtensionScopeType.READ_WRITE);
	assertEquals(extension.getDefinition(), ZoomOtherExtension.DEFINITION);

	GeoPackageExtensions.deleteTableExtensions(geoPackage, tableName);
	assertFalse(zoomOtherExtension.has(tableName));

}
 
Example 13
Source Project: geopackage-android-map   Source File: TestSetupTeardown.java    License: MIT License 4 votes vote down vote up
/**
 * 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);
	}

}
 
Example 14
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(TileMatrixSet tileMatrixSet) {

    if (tileMatrixSet == null) {
        throw new GeoPackageException("Non null "
                + TileMatrixSet.class.getSimpleName()
                + " is required to create " + TileDao.class.getSimpleName());
    }

    // Get the Tile Matrix collection, order by zoom level ascending & pixel
    // size descending per requirement 51
    List<TileMatrix> tileMatrices;
    try {
        TileMatrixDao tileMatrixDao = getTileMatrixDao();
        QueryBuilder<TileMatrix, TileMatrixKey> qb = tileMatrixDao
                .queryBuilder();
        qb.where().eq(TileMatrix.COLUMN_TABLE_NAME,
                tileMatrixSet.getTableName());
        qb.orderBy(TileMatrix.COLUMN_ZOOM_LEVEL, true);
        qb.orderBy(TileMatrix.COLUMN_PIXEL_X_SIZE, false);
        qb.orderBy(TileMatrix.COLUMN_PIXEL_Y_SIZE, false);
        PreparedQuery<TileMatrix> query = qb.prepare();
        tileMatrices = tileMatrixDao.query(query);
    } catch (SQLException e) {
        throw new GeoPackageException("Failed to retrieve "
                + TileDao.class.getSimpleName() + " for table name: "
                + tileMatrixSet.getTableName() + ". Exception retrieving "
                + TileMatrix.class.getSimpleName() + " collection.", e);
    }

    // Read the existing table and create the dao
    TileTableReader tableReader = new TileTableReader(
            tileMatrixSet.getTableName());
    final TileTable tileTable = tableReader.readTable(database);
    tileTable.setContents(tileMatrixSet.getContents());
    TileDao dao = new TileDao(getName(), database, tileMatrixSet, tileMatrices,
            tileTable);

    // Register the table name (with and without quotes) to wrap cursors with the tile cursor
    registerCursorWrapper(tileMatrixSet.getTableName(),
            new GeoPackageCursorWrapper() {

                @Override
                public Cursor wrapCursor(Cursor cursor) {
                    return new TileCursor(tileTable, cursor);
                }
            });

    return dao;
}
 
Example 15
Source Project: geopackage-android   Source File: TestSetupTeardown.java    License: MIT License 4 votes vote down vote up
/**
 * 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();

    // 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();

    int matrixWidthAndHeight = 2;
    double pixelXSize = (tileMatrixSet.getMaxX() - tileMatrixSet.getMinX()) / (matrixWidthAndHeight * tileWidth);
    double pixelYSize = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / (matrixWidthAndHeight * tileHeight);

    // 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);
    }

}
 
Example 16
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void createTileTable(TileTable table) {
	createUserTable(table);
}
 
Example 17
Source Project: geopackage-java   Source File: GeoPackageImpl.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(TileMatrixSet tileMatrixSet) {

	if (tileMatrixSet == null) {
		throw new GeoPackageException(
				"Non null " + TileMatrixSet.class.getSimpleName()
						+ " is required to create "
						+ TileDao.class.getSimpleName());
	}

	// Get the Tile Matrix collection, order by zoom level ascending & pixel
	// size descending per requirement 51
	List<TileMatrix> tileMatrices;
	try {
		TileMatrixDao tileMatrixDao = getTileMatrixDao();
		QueryBuilder<TileMatrix, TileMatrixKey> qb = tileMatrixDao
				.queryBuilder();
		qb.where().eq(TileMatrix.COLUMN_TABLE_NAME,
				tileMatrixSet.getTableName());
		qb.orderBy(TileMatrix.COLUMN_ZOOM_LEVEL, true);
		qb.orderBy(TileMatrix.COLUMN_PIXEL_X_SIZE, false);
		qb.orderBy(TileMatrix.COLUMN_PIXEL_Y_SIZE, false);
		PreparedQuery<TileMatrix> query = qb.prepare();
		tileMatrices = tileMatrixDao.query(query);
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to retrieve " + TileDao.class.getSimpleName()
						+ " for table name: " + tileMatrixSet.getTableName()
						+ ". Exception retrieving "
						+ TileMatrix.class.getSimpleName() + " collection.",
				e);
	}

	// Read the existing table and create the dao
	TileTableReader tableReader = new TileTableReader(
			tileMatrixSet.getTableName());
	final TileTable tileTable = tableReader.readTable(database);
	tileTable.setContents(tileMatrixSet.getContents());
	TileDao dao = new TileDao(getName(), database, tileMatrixSet,
			tileMatrices, tileTable);

	return dao;
}
 
Example 18
Source Project: geopackage-java   Source File: TestSetupTeardown.java    License: MIT License 4 votes vote down vote up
/**
 * Set up create for tiles test
 * 
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(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();

	final int tileWidth = 256;
	final int tileHeight = 256;

	int matrixWidthAndHeight = 2;
	double pixelXSize = (tileMatrixSet.getMaxX() - tileMatrixSet.getMinX())
			/ (matrixWidthAndHeight * tileWidth);
	double pixelYSize = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY())
			/ (matrixWidthAndHeight * tileHeight);

	byte[] tileData = TestUtils.getTileBytes();

	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);
	}

}
 
Example 19
Source Project: geopackage-android-map   Source File: TestUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Build an example tile table
 *
 * @param tableName
 * @return
 */
public static TileTable buildTileTable(String tableName) {

    List<TileColumn> columns = TileTable.createRequiredColumns();

    TileTable table = new TileTable(tableName, columns);

    return table;
}
 
Example 20
Source Project: geopackage-android   Source File: TestUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Build an example tile table
 *
 * @param tableName
 * @return
 */
public static TileTable buildTileTable(String tableName) {

    List<TileColumn> columns = TileTable.createRequiredColumns();

    TileTable table = new TileTable(tableName, columns);

    return table;
}
 
Example 21
Source Project: geopackage-java   Source File: TestUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Build an example tile table
 * 
 * @param tableName
 * @return tile table
 */
public static TileTable buildTileTable(String tableName) {

	List<TileColumn> columns = TileTable.createRequiredColumns();

	TileTable table = new TileTable(tableName, columns);

	return table;
}
 
Example 22
Source Project: geopackage-core-java   Source File: RelatedTablesCoreExtension.java    License: MIT License 2 votes vote down vote up
/**
 * Adds a tiles relationship between the base table and user tiles related
 * table. Creates a default user mapping table and the tile table if needed.
 * 
 * @param baseTableName
 *            base table name
 * @param tileTable
 *            user tile table
 * @param mappingTableName
 *            user mapping table name
 * @return The relationship that was added
 * @since 3.2.0
 */
public ExtendedRelation addTilesRelationship(String baseTableName,
		TileTable tileTable, String mappingTableName) {
	return addRelationship(baseTableName, tileTable, mappingTableName);
}
 
Example 23
Source Project: geopackage-core-java   Source File: RelatedTablesCoreExtension.java    License: MIT License 2 votes vote down vote up
/**
 * Adds a tiles relationship between the base table and user tiles related
 * table. Creates the user mapping table and a tile table if needed.
 * 
 * @param baseTableName
 *            base table name
 * @param tileTable
 *            user tile table
 * @param userMappingTable
 *            user mapping table
 * @return The relationship that was added
 * @since 3.2.0
 */
public ExtendedRelation addTilesRelationship(String baseTableName,
		TileTable tileTable, UserMappingTable userMappingTable) {
	return addRelationship(baseTableName, tileTable, userMappingTable);
}
 
Example 24
Source Project: geopackage-core-java   Source File: GeoPackageCore.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new tile table
 * 
 * @param table
 *            tile table
 */
public void createTileTable(TileTable table);