Java Code Examples for mil.nga.geopackage.tiles.matrixset.TileMatrixSet#getMaxY()

The following examples show how to use mil.nga.geopackage.tiles.matrixset.TileMatrixSet#getMaxY() . 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: TileDaoUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Adjust the tile matrix lengths if needed. Check if the tile matrix width
 * and height need to expand to account for pixel * number of pixels fitting
 * into the tile matrix lengths
 * 
 * @param tileMatrixSet
 *            tile matrix set
 * @param tileMatrices
 *            tile matrices
 */
public static void adjustTileMatrixLengths(TileMatrixSet tileMatrixSet,
		List<TileMatrix> tileMatrices) {
	double tileMatrixWidth = tileMatrixSet.getMaxX()
			- tileMatrixSet.getMinX();
	double tileMatrixHeight = tileMatrixSet.getMaxY()
			- tileMatrixSet.getMinY();
	for (TileMatrix tileMatrix : tileMatrices) {
		int tempMatrixWidth = (int) (tileMatrixWidth / (tileMatrix
				.getPixelXSize() * tileMatrix.getTileWidth()));
		int tempMatrixHeight = (int) (tileMatrixHeight / (tileMatrix
				.getPixelYSize() * tileMatrix.getTileHeight()));
		if (tempMatrixWidth > tileMatrix.getMatrixWidth()) {
			tileMatrix.setMatrixWidth(tempMatrixWidth);
		}
		if (tempMatrixHeight > tileMatrix.getMatrixHeight()) {
			tileMatrix.setMatrixHeight(tempMatrixHeight);
		}
	}
}
 
Example 2
Source File: TestSetupTeardown.java    From geopackage-android with 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 3
Source File: TestSetupTeardown.java    From geopackage-java with 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);
	}

}