Java Code Examples for mil.nga.geopackage.tiles.matrix.TileMatrixDao#isTableExists()
The following examples show how to use
mil.nga.geopackage.tiles.matrix.TileMatrixDao#isTableExists() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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); } } } }