Java Code Examples for mil.nga.geopackage.tiles.matrix.TileMatrix#setTileHeight()
The following examples show how to use
mil.nga.geopackage.tiles.matrix.TileMatrix#setTileHeight() .
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: TestSetupTeardown.java From geopackage-android-map with MIT License | 4 votes |
/** * 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 2
Source File: TestSetupTeardown.java From geopackage-android with MIT License | 4 votes |
/** * 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: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createCoverageDataPngExtension(GeoPackage geoPackage) throws SQLException { BoundingBox bbox = new BoundingBox(-11667347.997449303, 4824705.2253603265, -11666125.00499674, 4825928.217812888); int contentsEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; int tileMatrixSetEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); srsDao.getOrCreateFromEpsg(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D); SpatialReferenceSystem contentsSrs = srsDao .getOrCreateFromEpsg(contentsEpsg); SpatialReferenceSystem tileMatrixSetSrs = srsDao .getOrCreateFromEpsg(tileMatrixSetEpsg); ProjectionTransform transform = tileMatrixSetSrs.getProjection() .getTransformation(contentsSrs.getProjection()); BoundingBox contentsBoundingBox = bbox; if (!transform.isSameProjection()) { contentsBoundingBox = bbox.transform(transform); } CoverageDataPng coverageData = CoverageDataPng .createTileTableWithMetadata(geoPackage, "coverage_png", contentsBoundingBox, contentsSrs.getId(), bbox, tileMatrixSetSrs.getId()); TileDao tileDao = coverageData.getTileDao(); TileMatrixSet tileMatrixSet = coverageData.getTileMatrixSet(); GriddedCoverageDao griddedCoverageDao = coverageData .getGriddedCoverageDao(); GriddedCoverage griddedCoverage = new GriddedCoverage(); griddedCoverage.setTileMatrixSet(tileMatrixSet); griddedCoverage.setDataType(GriddedCoverageDataType.INTEGER); griddedCoverage.setDataNull(new Double(Short.MAX_VALUE - Short.MIN_VALUE)); griddedCoverage .setGridCellEncodingType(GriddedCoverageEncodingType.CENTER); griddedCoverageDao.create(griddedCoverage); GriddedTileDao griddedTileDao = coverageData.getGriddedTileDao(); int width = 1; int height = 1; int tileWidth = 3; int tileHeight = 3; short[][] tilePixels = new short[tileHeight][tileWidth]; tilePixels[0][0] = (short) 1661.95; tilePixels[0][1] = (short) 1665.40; tilePixels[0][2] = (short) 1668.19; tilePixels[1][0] = (short) 1657.18; tilePixels[1][1] = (short) 1663.39; tilePixels[1][2] = (short) 1669.65; tilePixels[2][0] = (short) 1654.78; tilePixels[2][1] = (short) 1660.31; tilePixels[2][2] = (short) 1666.44; byte[] imageBytes = coverageData.drawTileData(tilePixels); TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(tileMatrixSet.getContents()); tileMatrix.setMatrixHeight(height); tileMatrix.setMatrixWidth(width); tileMatrix.setTileHeight(tileHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setPixelXSize((bbox.getMaxLongitude() - bbox .getMinLongitude()) / width / tileWidth); tileMatrix .setPixelYSize((bbox.getMaxLatitude() - bbox.getMinLatitude()) / height / tileHeight); tileMatrix.setZoomLevel(15); tileMatrixDao.create(tileMatrix); TileRow tileRow = tileDao.newRow(); tileRow.setTileColumn(0); tileRow.setTileRow(0); tileRow.setZoomLevel(tileMatrix.getZoomLevel()); tileRow.setTileData(imageBytes); long tileId = tileDao.create(tileRow); GriddedTile griddedTile = new GriddedTile(); griddedTile.setContents(tileMatrixSet.getContents()); griddedTile.setTableId(tileId); griddedTileDao.create(griddedTile); }
Example 4
Source File: TileMatrixUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test create * * @param geoPackage * @throws SQLException */ public static void testCreate(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); ContentsDao contentsDao = geoPackage.getContentsDao(); TileMatrixDao dao = geoPackage.getTileMatrixDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); // Retrieve a random srs List<SpatialReferenceSystem> results = srsDao.queryForAll(); SpatialReferenceSystem srs = null; if (!results.isEmpty()) { int random = (int) (Math.random() * results.size()); srs = results.get(random); } // Create a new contents Contents contents = new Contents(); contents.setTableName("test_contents"); contents.setDataType(ContentsDataType.TILES); contents.setIdentifier("test_contents"); contents.setDescription(""); // contents.setLastChange(new Date()); contents.setMinX(-180.0); contents.setMinY(-90.0); contents.setMaxX(180.0); contents.setMaxY(90.0); contents.setSrs(srs); // Create the user tile table geoPackage.createTileTable(TestUtils.buildTileTable(contents .getTableName())); contentsDao.create(contents); // Create new matrix tile int zoom = 3; int matrixWidth = 4; int matrixHeight = 5; int tileWidth = 128; int tileHeight = 256; double pixelXSize = 889.5; double pixelYSize = 900.1; TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(contents); tileMatrix.setZoomLevel(zoom); tileMatrix.setMatrixWidth(matrixWidth); tileMatrix.setMatrixHeight(matrixHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setTileHeight(tileHeight); tileMatrix.setPixelXSize(pixelXSize); tileMatrix.setPixelYSize(pixelYSize); dao.create(tileMatrix); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); // Verify saved matrix tile TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId()); TestCase.assertEquals(contents.getId(), queryTileMatrix.getTableName()); TestCase.assertEquals(zoom, queryTileMatrix.getZoomLevel()); TestCase.assertEquals(matrixWidth, queryTileMatrix.getMatrixWidth()); TestCase.assertEquals(matrixHeight, queryTileMatrix.getMatrixHeight()); TestCase.assertEquals(tileWidth, queryTileMatrix.getTileWidth()); TestCase.assertEquals(tileHeight, queryTileMatrix.getTileHeight()); TestCase.assertEquals(pixelXSize, queryTileMatrix.getPixelXSize()); TestCase.assertEquals(pixelYSize, queryTileMatrix.getPixelYSize()); TestCase.assertEquals(contents.getId(), queryTileMatrix .getContents().getId()); } }
Example 5
Source File: TestSetupTeardown.java From geopackage-java with MIT License | 4 votes |
/** * 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 6
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createCoverageDataPngExtension(GeoPackage geoPackage) throws SQLException { BoundingBox bbox = new BoundingBox(-11667347.997449303, 4824705.2253603265, -11666125.00499674, 4825928.217812888); int contentsEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; int tileMatrixSetEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); srsDao.getOrCreateFromEpsg( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D); SpatialReferenceSystem contentsSrs = srsDao .getOrCreateFromEpsg(contentsEpsg); SpatialReferenceSystem tileMatrixSetSrs = srsDao .getOrCreateFromEpsg(tileMatrixSetEpsg); ProjectionTransform transform = tileMatrixSetSrs.getProjection() .getTransformation(contentsSrs.getProjection()); BoundingBox contentsBoundingBox = bbox; if (!transform.isSameProjection()) { contentsBoundingBox = bbox.transform(transform); } CoverageDataPng coverageData = CoverageDataPng .createTileTableWithMetadata(geoPackage, "coverage_png", contentsBoundingBox, contentsSrs.getId(), bbox, tileMatrixSetSrs.getId()); TileDao tileDao = coverageData.getTileDao(); TileMatrixSet tileMatrixSet = coverageData.getTileMatrixSet(); GriddedCoverageDao griddedCoverageDao = coverageData .getGriddedCoverageDao(); GriddedCoverage griddedCoverage = new GriddedCoverage(); griddedCoverage.setTileMatrixSet(tileMatrixSet); griddedCoverage.setDataType(GriddedCoverageDataType.INTEGER); griddedCoverage .setDataNull(new Double(Short.MAX_VALUE - Short.MIN_VALUE)); griddedCoverage .setGridCellEncodingType(GriddedCoverageEncodingType.CENTER); griddedCoverageDao.create(griddedCoverage); GriddedTileDao griddedTileDao = coverageData.getGriddedTileDao(); int width = 1; int height = 1; int tileWidth = 3; int tileHeight = 3; short[][] tilePixels = new short[tileHeight][tileWidth]; tilePixels[0][0] = (short) 1661.95; tilePixels[0][1] = (short) 1665.40; tilePixels[0][2] = (short) 1668.19; tilePixels[1][0] = (short) 1657.18; tilePixels[1][1] = (short) 1663.39; tilePixels[1][2] = (short) 1669.65; tilePixels[2][0] = (short) 1654.78; tilePixels[2][1] = (short) 1660.31; tilePixels[2][2] = (short) 1666.44; byte[] imageBytes = coverageData.drawTileData(tilePixels); TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(tileMatrixSet.getContents()); tileMatrix.setMatrixHeight(height); tileMatrix.setMatrixWidth(width); tileMatrix.setTileHeight(tileHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix .setPixelXSize((bbox.getMaxLongitude() - bbox.getMinLongitude()) / width / tileWidth); tileMatrix.setPixelYSize((bbox.getMaxLatitude() - bbox.getMinLatitude()) / height / tileHeight); tileMatrix.setZoomLevel(15); tileMatrixDao.create(tileMatrix); TileRow tileRow = tileDao.newRow(); tileRow.setTileColumn(0); tileRow.setTileRow(0); tileRow.setZoomLevel(tileMatrix.getZoomLevel()); tileRow.setTileData(imageBytes); long tileId = tileDao.create(tileRow); GriddedTile griddedTile = new GriddedTile(); griddedTile.setContents(tileMatrixSet.getContents()); griddedTile.setTableId(tileId); griddedTileDao.create(griddedTile); }
Example 7
Source File: TileMatrixUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test create * * @param geoPackage * @throws SQLException */ public static void testCreate(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); ContentsDao contentsDao = geoPackage.getContentsDao(); TileMatrixDao dao = geoPackage.getTileMatrixDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); // Retrieve a random srs List<SpatialReferenceSystem> results = srsDao.queryForAll(); SpatialReferenceSystem srs = null; if (!results.isEmpty()) { int random = (int) (Math.random() * results.size()); srs = results.get(random); } // Create a new contents Contents contents = new Contents(); contents.setTableName("test_contents"); contents.setDataType(ContentsDataType.TILES); contents.setIdentifier("test_contents"); contents.setDescription(""); // contents.setLastChange(new Date()); contents.setMinX(-180.0); contents.setMinY(-90.0); contents.setMaxX(180.0); contents.setMaxY(90.0); contents.setSrs(srs); // Create the user tile table geoPackage.createTileTable(TestUtils.buildTileTable(contents .getTableName())); contentsDao.create(contents); // Create new matrix tile int zoom = 3; int matrixWidth = 4; int matrixHeight = 5; int tileWidth = 128; int tileHeight = 256; double pixelXSize = 889.5; double pixelYSize = 900.1; TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(contents); tileMatrix.setZoomLevel(zoom); tileMatrix.setMatrixWidth(matrixWidth); tileMatrix.setMatrixHeight(matrixHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setTileHeight(tileHeight); tileMatrix.setPixelXSize(pixelXSize); tileMatrix.setPixelYSize(pixelYSize); dao.create(tileMatrix); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); // Verify saved matrix tile TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId()); TestCase.assertEquals(contents.getId(), queryTileMatrix.getTableName()); TestCase.assertEquals(zoom, queryTileMatrix.getZoomLevel()); TestCase.assertEquals(matrixWidth, queryTileMatrix.getMatrixWidth()); TestCase.assertEquals(matrixHeight, queryTileMatrix.getMatrixHeight()); TestCase.assertEquals(tileWidth, queryTileMatrix.getTileWidth()); TestCase.assertEquals(tileHeight, queryTileMatrix.getTileHeight()); TestCase.assertEquals(pixelXSize, queryTileMatrix.getPixelXSize()); TestCase.assertEquals(pixelYSize, queryTileMatrix.getPixelYSize()); TestCase.assertEquals(contents.getId(), queryTileMatrix .getContents().getId()); } }