mil.nga.geopackage.extension.contents.ContentsId Java Examples

The following examples show how to use mil.nga.geopackage.extension.contents.ContentsId. 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 vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createContentsIdTable() {
	verifyWritable();

	boolean created = false;
	ContentsIdDao dao = getContentsIdDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createContentsId() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + ContentsId.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #2
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: ContentsIdUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Check if the contents ids contain the table
 *
 * @param contentsIds         contents ids
 * @param tableName           table name
 * @param contentsIdExtension contents id extension
 * @return true if contains
 */
private static boolean containsTable(List<ContentsId> contentsIds,
                                     String tableName, ContentsIdExtension contentsIdExtension) {

    boolean contains = false;

    for (ContentsId contentsId : contentsIds) {
        contains = contentsId.getTableName().equals(tableName);
        if (contains) {
            break;
        }
    }

    return contains;
}
 
Example #4
Source File: FeatureCoreStyleExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create a style extension relationship between a feature table and style
 * extension table
 * 
 * @param mappingTableName
 *            mapping table name
 * @param featureTable
 *            feature table name
 * @param baseTable
 *            base table name
 * @param relatedTable
 *            related table name
 */
private void createStyleRelationship(String mappingTableName,
		String featureTable, String baseTable, String relatedTable) {

	if (!hasStyleRelationship(mappingTableName, baseTable, relatedTable)) {

		// Create the extension
		getOrCreate(featureTable);

		if (baseTable.equals(ContentsId.TABLE_NAME)) {
			if (!contentsId.has()) {
				contentsId.getOrCreateExtension();
			}
		}

		StyleMappingTable mappingTable = new StyleMappingTable(
				mappingTableName);

		if (relatedTable.equals(StyleTable.TABLE_NAME)) {
			relatedTables.addAttributesRelationship(baseTable,
					new StyleTable(), mappingTable);
		} else {
			relatedTables.addMediaRelationship(baseTable, new IconTable(),
					mappingTable);
		}
	}

}
 
Example #5
Source File: ContentsIdUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Check if the contents ids contain the table
 * 
 * @param contentsIds
 *            contents ids
 * @param tableName
 *            table name
 * @param contentsIdExtension
 *            contents id extension
 * @return true if contains
 */
private static boolean containsTable(List<ContentsId> contentsIds,
		String tableName, ContentsIdExtension contentsIdExtension) {

	boolean contains = false;

	for (ContentsId contentsId : contentsIds) {
		contains = contentsId.getTableName().equals(tableName);
		if (contains) {
			break;
		}
	}

	return contains;
}
 
Example #6
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
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 #7
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
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 #8
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * 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 #9
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ContentsIdDao getContentsIdDao() {
	return createDao(ContentsId.class);
}
 
Example #10
Source File: FeatureCoreStyleExtension.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a feature table style relationship
 * 
 * @param featureTable
 *            feature table
 */
public void createTableStyleRelationship(String featureTable) {
	createStyleRelationship(
			getMappingTableName(TABLE_MAPPING_TABLE_STYLE, featureTable),
			featureTable, ContentsId.TABLE_NAME, StyleTable.TABLE_NAME);
}
 
Example #11
Source File: FeatureCoreStyleExtension.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Determine if a feature table style relationship exists
 * 
 * @param featureTable
 *            feature table
 * @return true if relationship exists
 */
public boolean hasTableStyleRelationship(String featureTable) {
	return hasStyleRelationship(
			getMappingTableName(TABLE_MAPPING_TABLE_STYLE, featureTable),
			ContentsId.TABLE_NAME, StyleTable.TABLE_NAME);
}
 
Example #12
Source File: FeatureCoreStyleExtension.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a feature table icon relationship
 * 
 * @param featureTable
 *            feature table
 */
public void createTableIconRelationship(String featureTable) {
	createStyleRelationship(
			getMappingTableName(TABLE_MAPPING_TABLE_ICON, featureTable),
			featureTable, ContentsId.TABLE_NAME, IconTable.TABLE_NAME);
}
 
Example #13
Source File: FeatureCoreStyleExtension.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Determine if a feature table icon relationship exists
 * 
 * @param featureTable
 *            feature table
 * @return true if relationship exists
 */
public boolean hasTableIconRelationship(String featureTable) {
	return hasStyleRelationship(
			getMappingTableName(TABLE_MAPPING_TABLE_ICON, featureTable),
			ContentsId.TABLE_NAME, IconTable.TABLE_NAME);
}