mil.nga.geopackage.core.contents.ContentsDao Java Examples
The following examples show how to use
mil.nga.geopackage.core.contents.ContentsDao.
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: GeoPackageImpl.java From geopackage-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(String tableName) { ContentsDao dao = getContentsDao(); Contents contents = null; try { contents = dao.queryForId(tableName); } catch (SQLException e) { throw new GeoPackageException("Failed to retrieve " + Contents.class.getSimpleName() + " for table name: " + tableName, e); } if (contents == null) { throw new GeoPackageException( "No Contents Table exists for table name: " + tableName); } return getAttributesDao(contents); }
Example #2
Source File: GeoPackageImpl.java From geopackage-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(String tableName) { ContentsDao dao = getContentsDao(); Contents contents = null; try { contents = dao.queryForId(tableName); } catch (SQLException e) { throw new GeoPackageException( "Failed to retrieve " + Contents.class.getSimpleName() + " for table name: " + tableName, e); } if (contents == null) { throw new GeoPackageException( "No Contents Table exists for table name: " + tableName); } return getAttributesDao(contents); }
Example #3
Source File: GeoPackageRepository.java From geopackage-mapcache-android with MIT License | 6 votes |
/** * Get table Contents object */ public Contents getTableContents(String gpName, String tableName) { GeoPackage geo = null; try{ geo = manager.open(gpName); if(geo != null) { ContentsDao contentsDao = geo.getContentsDao(); Contents contents = contentsDao.queryForId(tableName); return contents; } } catch (Exception e){ } finally { if(geo != null){ geo.close(); } } return null; }
Example #4
Source File: NGAExtensions.java From geopackage-core-java with MIT License | 6 votes |
/** * Delete the properties extension from the GeoPackage * * @param geoPackage * GeoPackage * @since 3.0.2 */ public static void deletePropertiesExtension(GeoPackageCore geoPackage) { ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); if (geoPackage.isTable(PropertiesCoreExtension.TABLE_NAME)) { ContentsDao contentsDao = geoPackage.getContentsDao(); contentsDao.deleteTable(PropertiesCoreExtension.TABLE_NAME); } try { if (extensionsDao.isTableExists()) { extensionsDao.deleteByExtension( PropertiesCoreExtension.EXTENSION_NAME, PropertiesCoreExtension.TABLE_NAME); } } catch (SQLException e) { throw new GeoPackageException( "Failed to delete Properties extension. GeoPackage: " + geoPackage.getName(), e); } }
Example #5
Source File: RelatedTablesCoreExtension.java From geopackage-core-java with MIT License | 6 votes |
/** * Set the contents in the user table * * @param table * user table */ public void setContents(UserTable<? extends UserColumn> table) { ContentsDao dao = geoPackage.getContentsDao(); Contents contents = null; try { contents = dao.queryForId(table.getTableName()); } catch (SQLException e) { throw new GeoPackageException( "Failed to retrieve " + Contents.class.getSimpleName() + " for table name: " + table.getTableName(), e); } if (contents == null) { throw new GeoPackageException( "No Contents Table exists for table name: " + table.getTableName()); } table.setContents(contents); }
Example #6
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getContentsBoundingBox(Projection projection) { ContentsDao contentsDao = getContentsDao(); BoundingBox boundingBox = contentsDao.getBoundingBox(projection); return boundingBox; }
Example #7
Source File: FeatureTileUtils.java From geopackage-java with MIT License | 5 votes |
public static void updateLastChange(GeoPackage geoPackage, FeatureDao featureDao) throws SQLException { Contents contents = featureDao.getGeometryColumns().getContents(); contents.setLastChange(new Date()); ContentsDao contentsDao = geoPackage.getContentsDao(); contentsDao.update(contents); }
Example #8
Source File: SpatialReferenceSystemDao.java From geopackage-core-java with MIT License | 5 votes |
/** * Get or create a Contents DAO * * @return contents dao * @throws SQLException * upon creation failure */ private ContentsDao getContentsDao() throws SQLException { if (contentsDao == null) { contentsDao = DaoManager .createDao(connectionSource, Contents.class); } return contentsDao; }
Example #9
Source File: SpatialReferenceSystemDao.java From geopackage-core-java with MIT License | 5 votes |
/** * Delete the Spatial Reference System, cascading * * @param srs * spatial reference system * @return deleted count * @throws SQLException * upon deletion failure */ public int deleteCascade(SpatialReferenceSystem srs) throws SQLException { int count = 0; if (srs != null) { // Delete Contents ForeignCollection<Contents> contentsCollection = srs.getContents(); if (!contentsCollection.isEmpty()) { ContentsDao dao = getContentsDao(); dao.deleteCascade(contentsCollection); } // Delete Geometry Columns GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { ForeignCollection<GeometryColumns> geometryColumnsCollection = srs .getGeometryColumns(); if (!geometryColumnsCollection.isEmpty()) { geometryColumnsDao.delete(geometryColumnsCollection); } } // Delete Tile Matrix Set TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao(); if (tileMatrixSetDao.isTableExists()) { ForeignCollection<TileMatrixSet> tileMatrixSetCollection = srs .getTileMatrixSet(); if (!tileMatrixSetCollection.isEmpty()) { tileMatrixSetDao.delete(tileMatrixSetCollection); } } // Delete count = delete(srs); } return count; }
Example #10
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public void deleteTable(String table) { verifyWritable(); GeoPackageExtensions.deleteTableExtensions(this, table); ContentsDao contentsDao = getContentsDao(); contentsDao.deleteTable(table); }
Example #11
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public ContentsDao getContentsDao() { ContentsDao dao = createDao(Contents.class); dao.setDatabase(database); return dao; }
Example #12
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getContentsBoundingBox(Projection projection, String table) { ContentsDao contentsDao = getContentsDao(); BoundingBox boundingBox = contentsDao.getBoundingBox(projection, table); return boundingBox; }
Example #13
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getContentsBoundingBox(String table) { ContentsDao contentsDao = getContentsDao(); BoundingBox boundingBox = contentsDao.getBoundingBox(table); return boundingBox; }
Example #14
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public Contents getTableContents(String table) { ContentsDao contentDao = getContentsDao(); Contents contents = null; try { contents = contentDao.queryForId(table); } catch (SQLException e) { throw new GeoPackageException( "Failed to retrieve table contents: " + table, e); } return contents; }
Example #15
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public List<String> getTables() { ContentsDao contentDao = getContentsDao(); List<String> tables; try { tables = contentDao.getTables(); } catch (SQLException e) { throw new GeoPackageException("Failed to retrieve tables", e); } return tables; }
Example #16
Source File: FeatureTableCoreIndex.java From geopackage-core-java with MIT License | 5 votes |
/** * Determine if the feature table is indexed * * @return true if indexed */ public boolean isIndexed() { boolean indexed = false; Extensions extension = getExtension(); if (extension != null) { ContentsDao contentsDao = geoPackage.getContentsDao(); try { Contents contents = contentsDao.queryForId(tableName); if (contents != null) { Date lastChange = contents.getLastChange(); TableIndexDao tableIndexDao = geoPackage.getTableIndexDao(); TableIndex tableIndex = tableIndexDao.queryForId(tableName); if (tableIndex != null) { Date lastIndexed = tableIndex.getLastIndexed(); indexed = lastIndexed != null && lastIndexed .getTime() >= lastChange.getTime(); } } } catch (SQLException e) { throw new GeoPackageException( "Failed to check if table is indexed, GeoPackage: " + geoPackage.getName() + ", Table Name: " + tableName, e); } } return indexed; }
Example #17
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public List<String> getTables(String type) { ContentsDao contentDao = getContentsDao(); List<String> tableNames; try { tableNames = contentDao.getTables(type); } catch (SQLException e) { throw new GeoPackageException( "Failed to retrieve " + type + " tables", e); } return tableNames; }
Example #18
Source File: ContentsIdExtension.java From geopackage-core-java with MIT License | 5 votes |
/** * Get or create if needed the extension * * @return extensions object */ public Extensions getOrCreateExtension() { // Create table geoPackage.createContentsIdTable(); Extensions extension = getOrCreate(EXTENSION_NAME, null, null, EXTENSION_DEFINITION, ExtensionScopeType.READ_WRITE); ContentsDao contentsDao = geoPackage.getContentsDao(); try { if (contentsDao.queryForId(ContentsId.TABLE_NAME) == null) { Contents contents = new Contents(); contents.setTableName(ContentsId.TABLE_NAME); contents.setDataTypeString(Extensions.TABLE_NAME); contents.setIdentifier(ContentsId.TABLE_NAME); contentsDao.create(contents); } } catch (SQLException e) { throw new GeoPackageException( "Failed to create contents entry for contents id. GeoPackage: " + geoPackage.getName(), e); } return extension; }
Example #19
Source File: ContentsIdExtension.java From geopackage-core-java with MIT License | 5 votes |
/** * Get by contents data type * * @param type * contents data type * @return contents ids */ public List<ContentsId> getIds(String type) { List<ContentsId> contentsIds = null; ContentsDao contentsDao = geoPackage.getContentsDao(); try { if (contentsIdDao.isTableExists()) { QueryBuilder<Contents, String> contentsQueryBuilder = contentsDao .queryBuilder(); QueryBuilder<ContentsId, Long> contentsIdQueryBuilder = contentsIdDao .queryBuilder(); contentsQueryBuilder.where().eq(Contents.COLUMN_DATA_TYPE, type); contentsIdQueryBuilder.join(contentsQueryBuilder); contentsIds = contentsIdQueryBuilder.query(); } else { contentsIds = new ArrayList<>(); } } catch (SQLException e) { throw new GeoPackageException( "Failed to query for contents id by contents data type. GeoPackage: " + geoPackage.getName() + ", Type: " + type, e); } return contentsIds; }
Example #20
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 #21
Source File: TileMatrixSetUtils.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(); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); TestCase.assertEquals(count, dao.getTileTables().size()); // 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 set 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()); dao.create(tileMatrixSet); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); TestCase.assertEquals(newCount, dao.getTileTables().size()); TestCase.assertTrue(dao.getTileTables().contains( contents.getTableName())); // Verify saved matrix tile set TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet .getId()); TestCase.assertEquals(contents.getId(), queryTileMatrixSet.getTableName()); TestCase.assertEquals(contents.getSrsId().longValue(), queryTileMatrixSet.getSrsId()); TestCase.assertEquals(contents.getMinX(), queryTileMatrixSet.getMinX()); TestCase.assertEquals(contents.getMinY(), queryTileMatrixSet.getMinY()); TestCase.assertEquals(contents.getMaxX(), queryTileMatrixSet.getMaxX()); TestCase.assertEquals(contents.getMaxY(), queryTileMatrixSet.getMaxY()); TestCase.assertEquals(contents.getId(), queryTileMatrixSet .getContents().getId()); TestCase.assertEquals(contents.getSrsId().longValue(), queryTileMatrixSet.getSrs().getId()); } }
Example #22
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 #23
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 #24
Source File: TransactionTest.java From geopackage-java with MIT License | 4 votes |
/** * Test an ORMLite transaction * * @param geoPackage * GeoPackage * @param successful * true for a successful transaction * @throws SQLException * upon error */ private void testORMLite(final GeoPackage geoPackage, final boolean successful) throws SQLException { final String tableName = "test_table"; final Contents contents = new Contents(); contents.setTableName(tableName); contents.setDataType(ContentsDataType.ATTRIBUTES); if (!geoPackage.isTable(tableName)) { geoPackage.execSQL("CREATE TABLE " + tableName + " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)"); } final SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); final ContentsDao contentsDao = geoPackage.getContentsDao(); long srsCount = srsDao.countOf(); long contentsCount = contentsDao.countOf(); Callable<Void> callable = new Callable<Void>() { public Void call() throws Exception { SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D(); contents.setSrs(srs); contentsDao.create(contents); if (!successful) { throw new SQLException(); } return null; } }; try { geoPackage.callInTransaction(callable); } catch (SQLException e) { if (successful) { TestCase.fail(e.getMessage()); } } TestCase.assertEquals(successful ? srsCount + 1 : srsCount, srsDao.countOf()); TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount, contentsDao.countOf()); TestCase.assertEquals(successful, geoPackage.isAttributeTable(tableName)); }
Example #25
Source File: GeometryColumnsUtils.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(); GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); TestCase.assertEquals(count, dao.getFeatureTables().size()); // 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.FEATURES); 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 feature table geoPackage.createFeatureTable(TestUtils.buildFeatureTable( contents.getTableName(), "geom", GeometryType.GEOMETRY)); contentsDao.create(contents); String columnName = "TEST_COLUMN_NAME"; GeometryType geometryType = GeometryType.POINT; byte z = 2; byte m = 2; // Create new geometry columns GeometryColumns geometryColumns = new GeometryColumns(); geometryColumns.setContents(contents); geometryColumns.setColumnName(columnName); geometryColumns.setGeometryType(geometryType); geometryColumns.setSrs(contents.getSrs()); geometryColumns.setZ(z); geometryColumns.setM(m); dao.create(geometryColumns); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); TestCase.assertEquals(newCount, dao.getFeatureTables().size()); TestCase.assertTrue(dao.getFeatureTables().contains( contents.getTableName())); // Verify saved geometry columns GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertEquals(contents.getId(), queryGeometryColumns.getTableName()); TestCase.assertEquals(columnName, queryGeometryColumns.getColumnName()); TestCase.assertEquals(geometryType, queryGeometryColumns.getGeometryType()); TestCase.assertEquals(contents.getSrsId().longValue(), queryGeometryColumns.getSrsId()); TestCase.assertEquals(z, queryGeometryColumns.getZ()); TestCase.assertEquals(m, queryGeometryColumns.getM()); TestCase.assertEquals(contents.getId(), queryGeometryColumns .getContents().getId()); TestCase.assertEquals(contents.getSrsId().longValue(), queryGeometryColumns.getSrs().getId()); } }
Example #26
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 #27
Source File: GeometryColumnsUtils.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(); GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); TestCase.assertEquals(count, dao.getFeatureTables().size()); // 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.FEATURES); 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 feature table geoPackage.createFeatureTable(TestUtils.buildFeatureTable( contents.getTableName(), "geom", GeometryType.GEOMETRY)); contentsDao.create(contents); String columnName = "TEST_COLUMN_NAME"; GeometryType geometryType = GeometryType.POINT; byte z = 2; byte m = 2; // Create new geometry columns GeometryColumns geometryColumns = new GeometryColumns(); geometryColumns.setContents(contents); geometryColumns.setColumnName(columnName); geometryColumns.setGeometryType(geometryType); geometryColumns.setSrs(contents.getSrs()); geometryColumns.setZ(z); geometryColumns.setM(m); dao.create(geometryColumns); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); TestCase.assertEquals(newCount, dao.getFeatureTables().size()); TestCase.assertTrue(dao.getFeatureTables().contains( contents.getTableName())); // Verify saved geometry columns GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertEquals(contents.getId(), queryGeometryColumns.getTableName()); TestCase.assertEquals(columnName, queryGeometryColumns.getColumnName()); TestCase.assertEquals(geometryType, queryGeometryColumns.getGeometryType()); TestCase.assertEquals(contents.getSrsId().longValue(), queryGeometryColumns.getSrsId()); TestCase.assertEquals(z, queryGeometryColumns.getZ()); TestCase.assertEquals(m, queryGeometryColumns.getM()); TestCase.assertEquals(contents.getId(), queryGeometryColumns .getContents().getId()); TestCase.assertEquals(contents.getSrsId().longValue(), queryGeometryColumns.getSrs().getId()); } }
Example #28
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * Test an ORMLite transaction * * @param geoPackage GeoPackage * @param successful true for a successful transaction * @throws SQLException upon error */ private void testORMLite(final GeoPackage geoPackage, final boolean successful) throws SQLException { final String tableName = "test_table"; final Contents contents = new Contents(); contents.setTableName(tableName); contents.setDataType(ContentsDataType.ATTRIBUTES); if (!geoPackage.isTable(tableName)) { geoPackage.execSQL("CREATE TABLE " + tableName + " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)"); } final SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); final ContentsDao contentsDao = geoPackage.getContentsDao(); long srsCount = srsDao.countOf(); long contentsCount = contentsDao.countOf(); Callable<Void> callable = new Callable<Void>() { public Void call() throws Exception { SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D(); contents.setSrs(srs); contentsDao.create(contents); if (!successful) { throw new SQLException(); } return null; } }; try { geoPackage.callInTransaction(callable); } catch (SQLException e) { if (successful) { TestCase.fail(e.getMessage()); } } TestCase.assertEquals(successful ? srsCount + 1 : srsCount, srsDao.countOf()); TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount, contentsDao.countOf()); TestCase.assertEquals(successful, geoPackage.isAttributeTable(tableName)); }
Example #29
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 #30
Source File: FeatureTileUtils.java From geopackage-android with MIT License | 4 votes |
public static void updateLastChange(GeoPackage geoPackage, FeatureDao featureDao) throws SQLException { Contents contents = featureDao.getGeometryColumns().getContents(); contents.setLastChange(new Date()); ContentsDao contentsDao = geoPackage.getContentsDao(); contentsDao.update(contents); }