Java Code Examples for mil.nga.geopackage.features.columns.GeometryColumnsDao#queryForId()
The following examples show how to use
mil.nga.geopackage.features.columns.GeometryColumnsDao#queryForId() .
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: 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 2
Source File: GeometryColumnsUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { List<GeometryColumns> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns int random = (int) (Math.random() * results.size()); GeometryColumns geometryColumns = results.get(random); // Delete the geometry columns dao.delete(geometryColumns); // Verify deleted GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertNull(queryGeometryColumns); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns random = (int) (Math.random() * results.size()); geometryColumns = results.get(random); // Find which geometry columns to delete QueryBuilder<GeometryColumns, TableColumnKey> qb = dao .queryBuilder(); qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedQuery<GeometryColumns> query = qb.prepare(); List<GeometryColumns> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<GeometryColumns, TableColumnKey> db = dao .deleteBuilder(); db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedDelete<GeometryColumns> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example 3
Source File: GeoPackageTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * Validate feature table with metadata * * @param geoPackage * @throws SQLException */ private static void validateFeatureTableWithMetadata(GeoPackage geoPackage, GeometryColumns geometryColumns, String idColumn, List<FeatureColumn> additionalColumns) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); GeometryColumns queryGeometryColumns = dao.queryForId(geometryColumns .getId()); TestCase.assertNotNull(queryGeometryColumns); TestCase.assertEquals(geometryColumns.getTableName(), queryGeometryColumns.getTableName()); TestCase.assertEquals(geometryColumns.getColumnName(), queryGeometryColumns.getColumnName()); TestCase.assertEquals(GeometryType.POINT, queryGeometryColumns.getGeometryType()); TestCase.assertEquals(geometryColumns.getZ(), queryGeometryColumns.getZ()); TestCase.assertEquals(geometryColumns.getM(), queryGeometryColumns.getM()); FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns .getTableName()); FeatureRow featureRow = featureDao.newRow(); TestCase.assertEquals( 2 + (additionalColumns != null ? additionalColumns.size() : 0), featureRow.columnCount()); if (idColumn == null) { idColumn = "id"; } TestCase.assertEquals(idColumn, featureRow.getColumnName(0)); TestCase.assertEquals(geometryColumns.getColumnName(), featureRow.getColumnName(1)); if (additionalColumns != null) { TestCase.assertEquals("test_text", featureRow.getColumnName(2)); TestCase.assertEquals("test_real", featureRow.getColumnName(3)); TestCase.assertEquals("test_boolean", featureRow.getColumnName(4)); TestCase.assertEquals("test_blob", featureRow.getColumnName(5)); TestCase.assertEquals("test_integer", featureRow.getColumnName(6)); TestCase.assertEquals("test_text_limited", featureRow.getColumnName(7)); TestCase.assertEquals("test_blob_limited", featureRow.getColumnName(8)); } }
Example 4
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 5
Source File: GeometryColumnsUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { List<GeometryColumns> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns int random = (int) (Math.random() * results.size()); GeometryColumns geometryColumns = results.get(random); // Delete the geometry columns dao.delete(geometryColumns); // Verify deleted GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertNull(queryGeometryColumns); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns random = (int) (Math.random() * results.size()); geometryColumns = results.get(random); // Find which geometry columns to delete QueryBuilder<GeometryColumns, TableColumnKey> qb = dao .queryBuilder(); qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedQuery<GeometryColumns> query = qb.prepare(); List<GeometryColumns> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<GeometryColumns, TableColumnKey> db = dao .deleteBuilder(); db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedDelete<GeometryColumns> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example 6
Source File: GeoPackageTestUtils.java From geopackage-java with MIT License | 4 votes |
/** * Validate feature table with metadata * * @param geoPackage * @throws SQLException */ private static void validateFeatureTableWithMetadata(GeoPackage geoPackage, GeometryColumns geometryColumns, String idColumn, List<FeatureColumn> additionalColumns) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertNotNull(queryGeometryColumns); TestCase.assertEquals(geometryColumns.getTableName(), queryGeometryColumns.getTableName()); TestCase.assertEquals(geometryColumns.getColumnName(), queryGeometryColumns.getColumnName()); TestCase.assertEquals(GeometryType.POINT, queryGeometryColumns.getGeometryType()); TestCase.assertEquals(geometryColumns.getZ(), queryGeometryColumns.getZ()); TestCase.assertEquals(geometryColumns.getM(), queryGeometryColumns.getM()); FeatureDao featureDao = geoPackage .getFeatureDao(geometryColumns.getTableName()); FeatureRow featureRow = featureDao.newRow(); TestCase.assertEquals( 2 + (additionalColumns != null ? additionalColumns.size() : 0), featureRow.columnCount()); if (idColumn == null) { idColumn = "id"; } TestCase.assertEquals(idColumn, featureRow.getColumnName(0)); TestCase.assertEquals(geometryColumns.getColumnName(), featureRow.getColumnName(1)); if (additionalColumns != null) { TestCase.assertEquals("test_text", featureRow.getColumnName(2)); TestCase.assertEquals("test_real", featureRow.getColumnName(3)); TestCase.assertEquals("test_boolean", featureRow.getColumnName(4)); TestCase.assertEquals("test_blob", featureRow.getColumnName(5)); TestCase.assertEquals("test_integer", featureRow.getColumnName(6)); TestCase.assertEquals("test_text_limited", featureRow.getColumnName(7)); TestCase.assertEquals("test_blob_limited", featureRow.getColumnName(8)); } }