mil.nga.geopackage.extension.related.ExtendedRelation Java Examples
The following examples show how to use
mil.nga.geopackage.extension.related.ExtendedRelation.
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: GeoPackageExample.java From geopackage-android with MIT License | 6 votes |
private static void createRelatedTablesFeaturesExtension( GeoPackage geoPackage, String tableName1, String tableName2) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create(tableName1 + "_" + tableName2, additionalMappingColumns); ExtendedRelation relation = relatedTables.addFeaturesRelationship( tableName1, tableName2, userMappingTable); insertRelatedTablesFeaturesExtensionRows(geoPackage, relation); }
Example #2
Source File: GeoPackageExample.java From geopackage-java with MIT License | 6 votes |
private static void createRelatedTablesFeaturesExtension( GeoPackage geoPackage, String tableName1, String tableName2) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create( tableName1 + "_" + tableName2, additionalMappingColumns); ExtendedRelation relation = relatedTables.addFeaturesRelationship( tableName1, tableName2, userMappingTable); insertRelatedTablesFeaturesExtensionRows(geoPackage, relation); }
Example #3
Source File: GeoPackageDaoManager.java From geopackage-core-java with MIT License | 6 votes |
/** * Unregister all GeoPackage DAO with the connection source * * @param connectionSource * connection source */ public static void unregisterDaos(ConnectionSource connectionSource) { // TODO when ormlite-core version > 5.1 is released, replace with: // "DaoManager.unregisterDaos(connectionSource);" // See https://github.com/j256/ormlite-core/pull/149 unregisterDao(connectionSource, Contents.class, SpatialReferenceSystem.class, SpatialReferenceSystemSfSql.class, SpatialReferenceSystemSqlMm.class, Extensions.class, GriddedCoverage.class, GriddedTile.class, GeometryIndex.class, TableIndex.class, FeatureTileLink.class, ExtendedRelation.class, TileScaling.class, GeometryColumns.class, GeometryColumnsSfSql.class, GeometryColumnsSqlMm.class, Metadata.class, MetadataReference.class, DataColumns.class, DataColumnConstraints.class, TileMatrix.class, TileMatrixSet.class, ContentsId.class); }
Example #4
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean createExtendedRelationsTable() { verifyWritable(); boolean created = false; ExtendedRelationsDao dao = getExtendedRelationsDao(); try { if (!dao.isTableExists()) { created = tableCreator.createExtendedRelations() > 0; } } catch (SQLException e) { throw new GeoPackageException("Failed to check if " + ExtendedRelation.class.getSimpleName() + " table exists and create it", e); } return created; }
Example #5
Source File: GeoPackageExample.java From geopackage-java with MIT License | 5 votes |
private static void insertRelatedTablesMediaPreviewExtensionRows( GeoPackage geoPackage, RelatedTablesExtension relatedTables) throws IOException { ContentsIdExtension contentsId = new ContentsIdExtension(geoPackage); MediaTable mediaTable = MediaTable.create("preview"); UserMappingTable userMappingTable = UserMappingTable .create("features_" + mediaTable.getTableName()); ExtendedRelation relation = relatedTables.addMediaRelationship( ContentsId.TABLE_NAME, mediaTable, userMappingTable); MediaDao mediaDao = relatedTables.getMediaDao(relation); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); for (String featureTable : geoPackage.getFeatureTables()) { long featureContentsId = contentsId.getOrCreateId(featureTable); FeaturePreview preview = new FeaturePreview(geoPackage, featureTable); preview.setManual(true); preview.setBufferPercentage(0.1); BufferedImage previewImage = preview.draw(); byte[] previewBytes = ImageUtils.writeImageToBytes(previewImage, ImageUtils.IMAGE_FORMAT_PNG); MediaRow mediaRow = mediaDao.newRow(); mediaRow.setData(previewBytes); mediaRow.setContentType("image/png"); long mediaRowId = mediaDao.create(mediaRow); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureContentsId); userMappingRow.setRelatedId(mediaRowId); userMappingDao.create(userMappingRow); } }
Example #6
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public ExtendedRelationsDao getExtendedRelationsDao() { return createDao(ExtendedRelation.class); }
Example #7
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createRelatedTablesTilesExtension( GeoPackage geoPackage) { String featureTable = "point2"; String tileTable = "nga"; RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create( featureTable + "_" + tileTable, additionalMappingColumns); ExtendedRelation relation = relatedTables.addTilesRelationship( featureTable, tileTable, userMappingTable); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); FeatureDao featureDao = geoPackage .getFeatureDao(relation.getBaseTableName()); TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName()); FeatureResultSet featureResultSet = featureDao.queryForAll(); while (featureResultSet.moveToNext()) { FeatureRow featureRow = featureResultSet.getRow(); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); TileResultSet tileResultSet = tileDao .queryForTile(tileDao.getMinZoom()); while (tileResultSet.moveToNext()) { TileRow tileRow = tileResultSet.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(tileRow.getId()); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, featureName); userMappingDao.create(userMappingRow); } tileResultSet.close(); } featureResultSet.close(); }
Example #8
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void insertRelatedTablesFeaturesExtensionRows( GeoPackage geoPackage, ExtendedRelation relation) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); FeatureDao featureDao1 = geoPackage .getFeatureDao(relation.getBaseTableName()); FeatureDao featureDao2 = geoPackage .getFeatureDao(relation.getRelatedTableName()); FeatureResultSet featureResultSet1 = featureDao1.queryForAll(); while (featureResultSet1.moveToNext()) { FeatureRow featureRow1 = featureResultSet1.getRow(); String featureName = featureRow1.getValue(TEXT_COLUMN).toString(); FeatureResultSet featureResultSet2 = featureDao2 .queryForEq(TEXT_COLUMN, featureName); while (featureResultSet2.moveToNext()) { FeatureRow featureRow2 = featureResultSet2.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow1.getId()); userMappingRow.setRelatedId(featureRow2.getId()); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, featureName); userMappingDao.create(userMappingRow); } featureResultSet2.close(); } featureResultSet1.close(); }
Example #9
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void insertRelatedTablesMediaExtensionRows( GeoPackage geoPackage, ExtendedRelation relation, String query, String name, String file, String contentType, String description, String source) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); FeatureDao featureDao = geoPackage .getFeatureDao(relation.getBaseTableName()); MediaDao mediaDao = relatedTables.getMediaDao(relation); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); MediaRow mediaRow = mediaDao.newRow(); mediaRow.setData(TestUtils.getTestFileBytes(file)); mediaRow.setContentType(contentType); RelatedTablesUtils.populateUserRow(mediaDao.getTable(), mediaRow, MediaTable.requiredColumns()); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.TITLE, name); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.DESCRIPTION, description); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.SOURCE, source); long mediaRowId = mediaDao.create(mediaRow); FeatureResultSet featureResultSet = featureDao.queryForLike(TEXT_COLUMN, query); while (featureResultSet.moveToNext()) { FeatureRow featureRow = featureResultSet.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(mediaRowId); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName + " - " + name); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName + " - " + description); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, source); userMappingDao.create(userMappingRow); } featureResultSet.close(); }
Example #10
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createRelatedTablesMediaExtension(GeoPackage geoPackage) throws IOException { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMediaColumns = RelatedTablesUtils .createAdditionalUserColumns(); MediaTable mediaTable = MediaTable.create("media", additionalMediaColumns); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); String tableName1 = "geometry1"; UserMappingTable userMappingTable1 = UserMappingTable.create( tableName1 + "_" + mediaTable.getTableName(), additionalMappingColumns); ExtendedRelation relation1 = relatedTables.addMediaRelationship( tableName1, mediaTable, userMappingTable1); insertRelatedTablesMediaExtensionRows(geoPackage, relation1, "BIT Systems%", "BIT Systems", "BITSystems_Logo.png", "image/png", "BIT Systems Logo", "http://www.bit-sys.com"); String tableName2 = "geometry2"; UserMappingTable userMappingTable2 = UserMappingTable.create( tableName2 + "_" + mediaTable.getTableName(), additionalMappingColumns); ExtendedRelation relation2 = relatedTables.addMediaRelationship( tableName2, mediaTable, userMappingTable2); insertRelatedTablesMediaExtensionRows(geoPackage, relation2, "NGA%", "NGA", "NGA_Logo.png", "image/png", "NGA Logo", "http://www.nga.mil"); insertRelatedTablesMediaExtensionRows(geoPackage, relation2, "NGA", "NGA", "NGA.jpg", "image/jpeg", "Aerial View of NGA East", "http://www.nga.mil"); if (CONTENTS_ID) { insertRelatedTablesMediaPreviewExtensionRows(geoPackage, relatedTables); } }
Example #11
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createRelatedTablesMediaExtension(Activity activity, Context testContext, GeoPackage geoPackage) throws IOException { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMediaColumns = RelatedTablesUtils .createAdditionalUserColumns(); MediaTable mediaTable = MediaTable.create("media", additionalMediaColumns); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); String tableName1 = "geometry1"; UserMappingTable userMappingTable1 = UserMappingTable.create(tableName1 + "_" + mediaTable.getTableName(), additionalMappingColumns); ExtendedRelation relation1 = relatedTables.addMediaRelationship( tableName1, mediaTable, userMappingTable1); insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation1, "BIT Systems%", "BIT Systems", "BITSystems_Logo.png", "image/png", "BIT Systems Logo", "http://www.bit-sys.com"); String tableName2 = "geometry2"; UserMappingTable userMappingTable2 = UserMappingTable.create(tableName2 + "_" + mediaTable.getTableName(), additionalMappingColumns); ExtendedRelation relation2 = relatedTables.addMediaRelationship( tableName2, mediaTable, userMappingTable2); insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation2, "NGA%", "NGA", "NGA_Logo.png", "image/png", "NGA Logo", "http://www.nga.mil"); insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation2, "NGA", "NGA", "NGA.jpg", "image/jpeg", "Aerial View of NGA East", "http://www.nga.mil"); if (CONTENTS_ID) { insertRelatedTablesMediaPreviewExtensionRows(activity, geoPackage, relatedTables); } }
Example #12
Source File: GeoPackageExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the Related Tables extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyRelatedTables(GeoPackageCore geoPackage, String table, String newTable) { try { RelatedTablesCoreExtension relatedTablesExtension = getRelatedTableExtension( geoPackage); if (relatedTablesExtension.has()) { ExtendedRelationsDao extendedRelationsDao = relatedTablesExtension .getExtendedRelationsDao(); ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); List<ExtendedRelation> extendedRelations = extendedRelationsDao .getBaseTableRelations(table); for (ExtendedRelation extendedRelation : extendedRelations) { String mappingTableName = extendedRelation .getMappingTableName(); List<Extensions> extensions = extensionsDao .queryByExtension( RelatedTablesCoreExtension.EXTENSION_NAME, mappingTableName); if (!extensions.isEmpty()) { String newMappingTableName = CoreSQLUtils.createName( geoPackage.getDatabase(), mappingTableName, table, newTable); UserCustomTable userTable = UserCustomTableReader .readTable(geoPackage.getDatabase(), mappingTableName); AlterTable.copyTable(geoPackage.getDatabase(), userTable, newMappingTableName); Extensions extension = extensions.get(0); extension.setTableName(newMappingTableName); extensionsDao.create(extension); TableMapping extendedRelationTableMapping = new TableMapping( geoPackage.getDatabase(), ExtendedRelation.TABLE_NAME); extendedRelationTableMapping .removeColumn(ExtendedRelation.COLUMN_ID); MappedColumn baseTableNameColumn = extendedRelationTableMapping .getColumn( ExtendedRelation.COLUMN_BASE_TABLE_NAME); baseTableNameColumn.setConstantValue(newTable); baseTableNameColumn.setWhereValue(table); MappedColumn mappingTableNameColumn = extendedRelationTableMapping .getColumn( ExtendedRelation.COLUMN_MAPPING_TABLE_NAME); mappingTableNameColumn .setConstantValue(newMappingTableName); mappingTableNameColumn.setWhereValue(mappingTableName); CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), extendedRelationTableMapping); } } } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Related Tables for table: " + newTable + ", copied from table: " + table, e); } }
Example #13
Source File: NGAExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the feature table style * * @param featureStyleExtension * feature style extension * @param mappingTablePrefix * mapping table prefix * @param table * table name * @param newTable * new table name * @param contentsId * contents id * @param newContentsId * new contents id */ private static void copyFeatureTableStyle( FeatureCoreStyleExtension featureStyleExtension, String mappingTablePrefix, String table, String newTable, long contentsId, long newContentsId) throws SQLException { GeoPackageCore geoPackage = featureStyleExtension.getGeoPackage(); String mappingTableName = featureStyleExtension .getMappingTableName(mappingTablePrefix, table); ExtensionsDao extensionsDao = featureStyleExtension.getExtensionsDao(); List<Extensions> extensions = extensionsDao.queryByExtension( RelatedTablesCoreExtension.EXTENSION_NAME, mappingTableName); if (!extensions.isEmpty()) { String newMappingTableName = featureStyleExtension .getMappingTableName(mappingTablePrefix, newTable); UserCustomTable userTable = UserCustomTableReader .readTable(geoPackage.getDatabase(), mappingTableName); AlterTable.copyTable(geoPackage.getDatabase(), userTable, newMappingTableName, false); TableMapping mappingTableTableMapping = new TableMapping(userTable, newMappingTableName); MappedColumn baseIdColumn = mappingTableTableMapping .getColumn(UserMappingTable.COLUMN_BASE_ID); baseIdColumn.setConstantValue(newContentsId); baseIdColumn.setWhereValue(contentsId); CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), mappingTableTableMapping); Extensions extension = extensions.get(0); extension.setTableName(newMappingTableName); extensionsDao.create(extension); TableMapping extendedRelationTableMapping = new TableMapping( geoPackage.getDatabase(), ExtendedRelation.TABLE_NAME); extendedRelationTableMapping .removeColumn(ExtendedRelation.COLUMN_ID); MappedColumn baseTableNameColumn = extendedRelationTableMapping .getColumn(ExtendedRelation.COLUMN_BASE_TABLE_NAME); baseTableNameColumn.setWhereValue(ContentsId.TABLE_NAME); MappedColumn mappingTableNameColumn = extendedRelationTableMapping .getColumn(ExtendedRelation.COLUMN_MAPPING_TABLE_NAME); mappingTableNameColumn.setConstantValue(newMappingTableName); mappingTableNameColumn.setWhereValue(mappingTableName); CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), extendedRelationTableMapping); } }
Example #14
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createRelatedTablesTilesExtension( GeoPackage geoPackage) { String featureTable = "point2"; String tileTable = "nga"; RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create( featureTable + "_" + tileTable, additionalMappingColumns); ExtendedRelation relation = relatedTables.addTilesRelationship( featureTable, tileTable, userMappingTable); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); FeatureDao featureDao = geoPackage .getFeatureDao(relation.getBaseTableName()); TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName()); FeatureCursor featureCursor = featureDao.queryForAll(); while (featureCursor.moveToNext()) { FeatureRow featureRow = featureCursor.getRow(); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); TileCursor tileCursor = tileDao .queryForTile(tileDao.getMinZoom()); while (tileCursor.moveToNext()) { TileRow tileRow = tileCursor.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(tileRow.getId()); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, featureName); userMappingDao.create(userMappingRow); } tileCursor.close(); } featureCursor.close(); }
Example #15
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void insertRelatedTablesFeaturesExtensionRows( GeoPackage geoPackage, ExtendedRelation relation) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); FeatureDao featureDao1 = geoPackage.getFeatureDao(relation .getBaseTableName()); FeatureDao featureDao2 = geoPackage.getFeatureDao(relation .getRelatedTableName()); FeatureCursor featureCursor1 = featureDao1.queryForAll(); while (featureCursor1.moveToNext()) { FeatureRow featureRow1 = featureCursor1.getRow(); String featureName = featureRow1.getValue(TEXT_COLUMN).toString(); FeatureCursor featureCursor2 = featureDao2.queryForEq( TEXT_COLUMN, featureName); while (featureCursor2.moveToNext()) { FeatureRow featureRow2 = featureCursor2.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow1.getId()); userMappingRow.setRelatedId(featureRow2.getId()); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, featureName); userMappingDao.create(userMappingRow); } featureCursor2.close(); } featureCursor1.close(); }
Example #16
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void insertRelatedTablesMediaPreviewExtensionRows(Activity activity, GeoPackage geoPackage, RelatedTablesExtension relatedTables) throws IOException { ContentsIdExtension contentsId = new ContentsIdExtension(geoPackage); MediaTable mediaTable = MediaTable.create("preview"); UserMappingTable userMappingTable = UserMappingTable .create("features_" + mediaTable.getTableName()); ExtendedRelation relation = relatedTables.addMediaRelationship( ContentsId.TABLE_NAME, mediaTable, userMappingTable); MediaDao mediaDao = relatedTables.getMediaDao(relation); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); for (String featureTable : geoPackage.getFeatureTables()) { long featureContentsId = contentsId.getOrCreateId(featureTable); FeaturePreview preview = new FeaturePreview(activity, geoPackage, featureTable); try { preview.setManual(true); preview.setBufferPercentage(0.1); Bitmap previewImage = preview.draw(); byte[] previewBytes = BitmapConverter.toBytes(previewImage, Bitmap.CompressFormat.PNG); MediaRow mediaRow = mediaDao.newRow(); mediaRow.setData(previewBytes); mediaRow.setContentType("image/png"); long mediaRowId = mediaDao.create(mediaRow); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureContentsId); userMappingRow.setRelatedId(mediaRowId); userMappingDao.create(userMappingRow); } finally { preview.close(); } } }
Example #17
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void insertRelatedTablesMediaExtensionRows(Activity activity, Context testContext, GeoPackage geoPackage, ExtendedRelation relation, String query, String name, String file, String contentType, String description, String source) throws IOException { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); FeatureDao featureDao = geoPackage.getFeatureDao(relation .getBaseTableName()); MediaDao mediaDao = relatedTables.getMediaDao(relation); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); MediaRow mediaRow = mediaDao.newRow(); TestUtils.copyAssetFileToInternalStorage(activity, testContext, file); String mediaImageName = TestUtils.getAssetFileInternalStorageLocation(activity, file); Bitmap mediaImage = BitmapFactory.decodeFile(mediaImageName); mediaRow.setData(mediaImage, Bitmap.CompressFormat.PNG); mediaRow.setContentType(contentType); RelatedTablesUtils.populateUserRow(mediaDao.getTable(), mediaRow, MediaTable.requiredColumns()); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.TITLE, name); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.DESCRIPTION, description); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.SOURCE, source); long mediaRowId = mediaDao.create(mediaRow); FeatureCursor featureCursor = featureDao.queryForLike( TEXT_COLUMN, query); while (featureCursor.moveToNext()) { FeatureRow featureRow = featureCursor.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(mediaRowId); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName + " - " + name); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName + " - " + description); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, source); userMappingDao.create(userMappingRow); } featureCursor.close(); }