mil.nga.geopackage.tiles.matrix.TileMatrixDao Java Examples
The following examples show how to use
mil.nga.geopackage.tiles.matrix.TileMatrixDao.
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: ContentsDao.java From geopackage-core-java with MIT License | 6 votes |
/** * Verify the required tile tables exist * * @param dataType * data type * @throws SQLException * upon tiles verification error */ private void verifyTiles(ContentsDataType dataType) throws SQLException { // Tiles require Tile Matrix Set table (Spec Requirement 37) TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao(); if (!tileMatrixSetDao.isTableExists()) { throw new GeoPackageException("A data type of " + dataType.getName() + " requires the " + TileMatrixSet.class.getSimpleName() + " table to first be created using the GeoPackage."); } // Tiles require Tile Matrix table (Spec Requirement 41) TileMatrixDao tileMatrixDao = getTileMatrixDao(); if (!tileMatrixDao.isTableExists()) { throw new GeoPackageException("A data type of " + dataType.getName() + " requires the " + TileMatrix.class.getSimpleName() + " table to first be created using the GeoPackage."); } }
Example #2
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean createTileMatrixTable() { verifyWritable(); boolean created = false; TileMatrixDao dao = getTileMatrixDao(); try { if (!dao.isTableExists()) { created = tableCreator.createTileMatrix() > 0; } } catch (SQLException e) { throw new GeoPackageException( "Failed to check if " + TileMatrix.class.getSimpleName() + " table exists and create it", e); } return created; }
Example #3
Source File: ContentsDao.java From geopackage-core-java with MIT License | 5 votes |
/** * Get or create a Tile Matrix DAO * * @return tile matrix dao * @throws SQLException * upon dao creation failure */ private TileMatrixDao getTileMatrixDao() throws SQLException { if (tileMatrixDao == null) { tileMatrixDao = DaoManager.createDao(connectionSource, TileMatrix.class); } return tileMatrixDao; }
Example #4
Source File: GeoPackageImpl.java From geopackage-android with MIT License | 4 votes |
/** * {@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 #5
Source File: GeoPackageTestUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test deleting tables by name * * @param geoPackage * @throws SQLException */ public static void testDeleteTables(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); ContentsDao contentsDao = geoPackage.getContentsDao(); TestCase.assertTrue(geometryColumnsDao.isTableExists() || tileMatrixSetDao.isTableExists()); geoPackage.foreignKeys(false); if (geometryColumnsDao.isTableExists()) { TestCase.assertEquals(geoPackage.getFeatureTables().size(), geometryColumnsDao.countOf()); for (String featureTable : geoPackage.getFeatureTables()) { TestCase.assertTrue(geoPackage.isTable(featureTable)); TestCase.assertNotNull(contentsDao.queryForId(featureTable)); geoPackage.deleteTable(featureTable); TestCase.assertFalse(geoPackage.isTable(featureTable)); TestCase.assertNull(contentsDao.queryForId(featureTable)); } TestCase.assertEquals(0, geometryColumnsDao.countOf()); geoPackage.dropTable(GeometryColumns.TABLE_NAME); TestCase.assertFalse(geometryColumnsDao.isTableExists()); } if (tileMatrixSetDao.isTableExists()) { TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TestCase.assertTrue(tileMatrixSetDao.isTableExists()); TestCase.assertTrue(tileMatrixDao.isTableExists()); TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES) .size() + geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE) .size(), tileMatrixSetDao.countOf()); for (String tileTable : geoPackage.getTileTables()) { TestCase.assertTrue(geoPackage.isTable(tileTable)); TestCase.assertNotNull(contentsDao.queryForId(tileTable)); geoPackage.deleteTable(tileTable); TestCase.assertFalse(geoPackage.isTable(tileTable)); TestCase.assertNull(contentsDao.queryForId(tileTable)); } TestCase.assertEquals(geoPackage .getTables(ContentsDataType.GRIDDED_COVERAGE).size(), tileMatrixSetDao.countOf()); geoPackage.dropTable(TileMatrix.TABLE_NAME); geoPackage.dropTable(TileMatrixSet.TABLE_NAME); TestCase.assertFalse(tileMatrixSetDao.isTableExists()); TestCase.assertFalse(tileMatrixDao.isTableExists()); } for (String attributeTable : geoPackage.getAttributesTables()) { TestCase.assertTrue(geoPackage.isTable(attributeTable)); TestCase.assertNotNull(contentsDao.queryForId(attributeTable)); geoPackage.deleteTable(attributeTable); TestCase.assertFalse(geoPackage.isTable(attributeTable)); TestCase.assertNull(contentsDao.queryForId(attributeTable)); } }
Example #6
Source File: TileMatrixUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { TileMatrixDao dao = geoPackage.getTileMatrixDao(); if (dao.isTableExists()) { List<TileMatrix> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix int random = (int) (Math.random() * results.size()); TileMatrix tileMatrix = results.get(random); // Delete the tile matrix dao.delete(tileMatrix); // Verify deleted TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId()); TestCase.assertNull(queryTileMatrix); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix random = (int) (Math.random() * results.size()); tileMatrix = results.get(random); // Find which tile matrix to delete QueryBuilder<TileMatrix, TileMatrixKey> qb = dao .queryBuilder(); qb.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedQuery<TileMatrix> query = qb.prepare(); List<TileMatrix> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<TileMatrix, TileMatrixKey> db = dao .deleteBuilder(); db.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedDelete<TileMatrix> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
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()); } }
Example #8
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 #9
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 #10
Source File: GeoPackageImpl.java From geopackage-java with MIT License | 4 votes |
/** * {@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 #11
Source File: ContentsDao.java From geopackage-core-java with MIT License | 4 votes |
/** * Delete the Contents, cascading * * @param contents * contents * @return deleted count * @throws SQLException * upon deletion error */ public int deleteCascade(Contents contents) throws SQLException { int count = 0; if (contents != null) { ContentsDataType dataType = contents.getDataType(); if (dataType != null) { switch (dataType) { case FEATURES: // Delete Geometry Columns GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { GeometryColumns geometryColumns = contents .getGeometryColumns(); if (geometryColumns != null) { geometryColumnsDao.delete(geometryColumns); } } break; case TILES: case GRIDDED_COVERAGE: // Delete Tile Matrix collection TileMatrixDao tileMatrixDao = getTileMatrixDao(); if (tileMatrixDao.isTableExists()) { ForeignCollection<TileMatrix> tileMatrixCollection = contents .getTileMatrix(); if (!tileMatrixCollection.isEmpty()) { tileMatrixDao.delete(tileMatrixCollection); } } // Delete Tile Matrix Set TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao(); if (tileMatrixSetDao.isTableExists()) { TileMatrixSet tileMatrixSet = contents .getTileMatrixSet(); if (tileMatrixSet != null) { tileMatrixSetDao.delete(tileMatrixSet); } } break; case ATTRIBUTES: dropTable(contents.getTableName()); break; } } else { dropTable(contents.getTableName()); } count = delete(contents); } return count; }
Example #12
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public TileMatrixDao getTileMatrixDao() { return createDao(TileMatrix.class); }
Example #13
Source File: GeoPackageTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test deleting tables by name * * @param geoPackage * @throws SQLException */ public static void testDeleteTables(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); ContentsDao contentsDao = geoPackage.getContentsDao(); TestCase.assertTrue(geometryColumnsDao.isTableExists() || tileMatrixSetDao.isTableExists()); geoPackage.foreignKeys(false); if (geometryColumnsDao.isTableExists()) { TestCase.assertEquals(geoPackage.getFeatureTables().size(), geometryColumnsDao.countOf()); for (String featureTable : geoPackage.getFeatureTables()) { TestCase.assertTrue(geoPackage.isTable(featureTable)); TestCase.assertNotNull(contentsDao.queryForId(featureTable)); geoPackage.deleteTable(featureTable); TestCase.assertFalse(geoPackage.isTable(featureTable)); TestCase.assertNull(contentsDao.queryForId(featureTable)); } TestCase.assertEquals(0, geometryColumnsDao.countOf()); geoPackage.dropTable(GeometryColumns.TABLE_NAME); TestCase.assertFalse(geometryColumnsDao.isTableExists()); } if (tileMatrixSetDao.isTableExists()) { TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TestCase.assertTrue(tileMatrixSetDao.isTableExists()); TestCase.assertTrue(tileMatrixDao.isTableExists()); TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES).size() + geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(), tileMatrixSetDao.countOf()); for (String tileTable : geoPackage.getTileTables()) { TestCase.assertTrue(geoPackage.isTable(tileTable)); TestCase.assertNotNull(contentsDao.queryForId(tileTable)); geoPackage.deleteTable(tileTable); TestCase.assertFalse(geoPackage.isTable(tileTable)); TestCase.assertNull(contentsDao.queryForId(tileTable)); } TestCase.assertEquals(geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(), tileMatrixSetDao.countOf()); geoPackage.dropTable(TileMatrix.TABLE_NAME); geoPackage.dropTable(TileMatrixSet.TABLE_NAME); TestCase.assertFalse(tileMatrixSetDao.isTableExists()); TestCase.assertFalse(tileMatrixDao.isTableExists()); } for (String attributeTable : geoPackage.getAttributesTables()) { TestCase.assertTrue(geoPackage.isTable(attributeTable)); TestCase.assertNotNull(contentsDao.queryForId(attributeTable)); geoPackage.deleteTable(attributeTable); TestCase.assertFalse(geoPackage.isTable(attributeTable)); TestCase.assertNull(contentsDao.queryForId(attributeTable)); } }
Example #14
Source File: TileMatrixUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { TileMatrixDao dao = geoPackage.getTileMatrixDao(); if (dao.isTableExists()) { List<TileMatrix> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix int random = (int) (Math.random() * results.size()); TileMatrix tileMatrix = results.get(random); // Delete the tile matrix dao.delete(tileMatrix); // Verify deleted TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId()); TestCase.assertNull(queryTileMatrix); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix random = (int) (Math.random() * results.size()); tileMatrix = results.get(random); // Find which tile matrix to delete QueryBuilder<TileMatrix, TileMatrixKey> qb = dao .queryBuilder(); qb.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedQuery<TileMatrix> query = qb.prepare(); List<TileMatrix> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<TileMatrix, TileMatrixKey> db = dao .deleteBuilder(); db.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedDelete<TileMatrix> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example #15
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 #16
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 #17
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 #18
Source File: CoverageDataTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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(); } } }
Example #19
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 #20
Source File: GeoPackageCore.java From geopackage-core-java with MIT License | 2 votes |
/** * Get a Tile Matrix DAO * * @return Tile Matrix DAO */ public TileMatrixDao getTileMatrixDao();