mil.nga.geopackage.attributes.AttributesColumn Java Examples

The following examples show how to use mil.nga.geopackage.attributes.AttributesColumn. 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 AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints) {

	if (idColumnName == null) {
		idColumnName = "id";
	}

	List<AttributesColumn> columns = new ArrayList<AttributesColumn>();
	columns.add(AttributesColumn.createPrimaryKeyColumn(idColumnName));

	if (additionalColumns != null) {
		columns.addAll(additionalColumns);
	}

	return createAttributesTable(tableName, columns, constraints);
}
 
Example #2
Source File: StyleTable.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the style columns
 * 
 * @return columns
 */
private static List<AttributesColumn> createColumns() {

	List<AttributesColumn> columns = new ArrayList<>();

	columns.add(AttributesColumn.createPrimaryKeyColumn(COLUMN_ID));
	columns.add(AttributesColumn.createColumn(COLUMN_NAME,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_DESCRIPTION,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_COLOR,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_OPACITY,
			GeoPackageDataType.REAL));
	columns.add(AttributesColumn.createColumn(COLUMN_WIDTH,
			GeoPackageDataType.REAL));
	columns.add(AttributesColumn.createColumn(COLUMN_FILL_COLOR,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_FILL_OPACITY,
			GeoPackageDataType.REAL));

	return columns;
}
 
Example #3
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns) {
	return createAttributesTable(tableName, idColumnName, additionalColumns,
			null);
}
 
Example #4
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints) {
	return createAttributesTable(tableName, null, additionalColumns,
			constraints);
}
 
Example #5
Source File: PropertiesCoreExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @return extension
 */
public Extensions getOrCreate() {

	// Create the attributes table
	if (!geoPackage.isTable(TABLE_NAME)) {

		AttributesColumn propertyColumn = AttributesColumn.createColumn(
				COLUMN_PROPERTY, GeoPackageDataType.TEXT, true, null);
		AttributesColumn valueColumn = AttributesColumn
				.createColumn(COLUMN_VALUE, GeoPackageDataType.TEXT);

		List<AttributesColumn> additionalColumns = new ArrayList<>();
		additionalColumns.add(propertyColumn);
		additionalColumns.add(valueColumn);

		List<Constraint> constraints = new ArrayList<>();
		constraints.add(new UniqueConstraint(propertyColumn, valueColumn));

		geoPackage.createAttributesTableWithId(TABLE_NAME,
				additionalColumns, constraints);
	}

	Extensions extension = getOrCreate(EXTENSION_NAME, TABLE_NAME, null,
			EXTENSION_DEFINITION, ExtensionScopeType.READ_WRITE);

	return extension;
}
 
Example #6
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createAttributes(GeoPackage geoPackage) {

		List<AttributesColumn> columns = new ArrayList<AttributesColumn>();

		columns.add(AttributesColumn.createColumn(TEXT_COLUMN,
				GeoPackageDataType.TEXT, false, ""));
		columns.add(AttributesColumn.createColumn(REAL_COLUMN,
				GeoPackageDataType.REAL));
		columns.add(AttributesColumn.createColumn(BOOLEAN_COLUMN,
				GeoPackageDataType.BOOLEAN));
		columns.add(AttributesColumn.createColumn(BLOB_COLUMN,
				GeoPackageDataType.BLOB));
		columns.add(AttributesColumn.createColumn(INTEGER_COLUMN,
				GeoPackageDataType.INTEGER));
		columns.add(AttributesColumn.createColumn(TEXT_LIMITED_COLUMN,
				GeoPackageDataType.TEXT,
				(long) UUID.randomUUID().toString().length()));
		columns.add(AttributesColumn.createColumn(BLOB_LIMITED_COLUMN,
				GeoPackageDataType.BLOB,
				(long) UUID.randomUUID().toString().getBytes().length));
		columns.add(AttributesColumn.createColumn(DATE_COLUMN,
				GeoPackageDataType.DATE));
		columns.add(AttributesColumn.createColumn(DATETIME_COLUMN,
				GeoPackageDataType.DATETIME));

		AttributesTable attributesTable = geoPackage
				.createAttributesTableWithId("attributes", columns);

		AttributesDao attributesDao = geoPackage
				.getAttributesDao(attributesTable.getTableName());

		for (int i = 0; i < 10; i++) {

			AttributesRow newRow = attributesDao.newRow();

			newRow.setValue(TEXT_COLUMN, UUID.randomUUID().toString());
			newRow.setValue(REAL_COLUMN, Math.random() * 5000.0);
			newRow.setValue(BOOLEAN_COLUMN, Math.random() < .5 ? false : true);
			newRow.setValue(BLOB_COLUMN,
					UUID.randomUUID().toString().getBytes());
			newRow.setValue(INTEGER_COLUMN, (int) (Math.random() * 500));
			newRow.setValue(TEXT_LIMITED_COLUMN, UUID.randomUUID().toString());
			newRow.setValue(BLOB_LIMITED_COLUMN,
					UUID.randomUUID().toString().getBytes());
			newRow.setValue(DATE_COLUMN, new Date());
			newRow.setValue(DATETIME_COLUMN, new Date());

			attributesDao.create(newRow);

		}
	}
 
Example #7
Source File: AttributesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 * 
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
		AttributesRow attributesRow) {
	TestCase.assertEquals(columns.length, attributesRow.columnCount());

	for (int i = 0; i < attributesRow.columnCount(); i++) {
		AttributesColumn column = attributesRow.getTable().getColumns()
				.get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
		TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
		int rowType = attributesRow.getRowColumnType(i);
		Object value = attributesRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			if (dataType == GeoPackageDataType.DATE
					|| dataType == GeoPackageDataType.DATETIME) {
				TestCase.assertTrue(value instanceof Date);
				Date date = (Date) value;
				DateConverter converter = DateConverter.converter(dataType);
				String dateString = converter.stringValue(date);
				TestCase.assertEquals(date.getTime(),
						converter.dateValue(dateString).getTime());
			} else {
				TestCase.assertTrue(value instanceof String);
			}
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(attributesRow.getId() >= 0);
}
 
Example #8
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTable(String tableName,
		List<AttributesColumn> columns) {
	return createAttributesTable(tableName, columns, null);
}
 
Example #9
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns) {
	return createAttributesTable(tableName, null, additionalColumns);
}
 
Example #10
Source File: AttributesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 *
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
                                          AttributesRow attributesRow) {
    TestCase.assertEquals(columns.length, attributesRow.columnCount());

    for (int i = 0; i < attributesRow.columnCount(); i++) {
        AttributesColumn column = attributesRow.getTable().getColumns()
                .get(i);
        GeoPackageDataType dataType = column.getDataType();
        TestCase.assertEquals(i, column.getIndex());
        TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
        TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
        int rowType = attributesRow.getRowColumnType(i);
        Object value = attributesRow.getValue(i);

        switch (rowType) {

            case ResultUtils.FIELD_TYPE_INTEGER:
                TestUtils.validateIntegerValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_FLOAT:
                TestUtils.validateFloatValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_STRING:
                if (dataType == GeoPackageDataType.DATE || dataType == GeoPackageDataType.DATETIME) {
                    TestCase.assertTrue(value instanceof Date);
                    Date date = (Date) value;
                    DateConverter converter = DateConverter.converter(dataType);
                    String dateString = converter.stringValue(date);
                    TestCase.assertEquals(date.getTime(), converter.dateValue(dateString).getTime());
                } else {
                    TestCase.assertTrue(value instanceof String);
                }
                break;

            case ResultUtils.FIELD_TYPE_BLOB:
                TestCase.assertTrue(value instanceof byte[]);
                break;

            case ResultUtils.FIELD_TYPE_NULL:
                TestCase.assertNull(value);
                break;

        }
    }

    TestCase.assertTrue(attributesRow.getId() >= 0);
}
 
Example #11
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createAttributes(GeoPackage geoPackage) {

        List<AttributesColumn> columns = new ArrayList<AttributesColumn>();

        columns.add(AttributesColumn.createColumn(TEXT_COLUMN,
                GeoPackageDataType.TEXT, false, ""));
        columns.add(AttributesColumn.createColumn(REAL_COLUMN,
                GeoPackageDataType.REAL));
        columns.add(AttributesColumn.createColumn(BOOLEAN_COLUMN,
                GeoPackageDataType.BOOLEAN));
        columns.add(AttributesColumn.createColumn(BLOB_COLUMN,
                GeoPackageDataType.BLOB));
        columns.add(AttributesColumn.createColumn(INTEGER_COLUMN,
                GeoPackageDataType.INTEGER));
        columns.add(AttributesColumn.createColumn(TEXT_LIMITED_COLUMN,
                GeoPackageDataType.TEXT, (long) UUID.randomUUID().toString()
                        .length()));
        columns.add(AttributesColumn.createColumn(BLOB_LIMITED_COLUMN,
                GeoPackageDataType.BLOB, (long) UUID.randomUUID().toString()
                        .getBytes().length));
        columns.add(AttributesColumn.createColumn(DATE_COLUMN,
                GeoPackageDataType.DATE));
        columns.add(AttributesColumn.createColumn(DATETIME_COLUMN,
                GeoPackageDataType.DATETIME));

        AttributesTable attributesTable = geoPackage
                .createAttributesTableWithId("attributes", columns);

        AttributesDao attributesDao = geoPackage
                .getAttributesDao(attributesTable.getTableName());

        for (int i = 0; i < 10; i++) {

            AttributesRow newRow = attributesDao.newRow();

            newRow.setValue(TEXT_COLUMN, UUID.randomUUID().toString());
            newRow.setValue(REAL_COLUMN, Math.random() * 5000.0);
            newRow.setValue(BOOLEAN_COLUMN, Math.random() < .5 ? false : true);
            newRow.setValue(BLOB_COLUMN, UUID.randomUUID().toString()
                    .getBytes());
            newRow.setValue(INTEGER_COLUMN, (int) (Math.random() * 500));
            newRow.setValue(TEXT_LIMITED_COLUMN, UUID.randomUUID().toString());
            newRow.setValue(BLOB_LIMITED_COLUMN, UUID.randomUUID().toString()
                    .getBytes());
            newRow.setValue(DATE_COLUMN, new Date());
            newRow.setValue(DATETIME_COLUMN, new Date());

            attributesDao.create(newRow);

        }
    }
 
Example #12
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column named "id" and the provided additional columns.
 * 
 * @param tableName
 *            table name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @return attributes table
 * @since 1.2.1
 */
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns);
 
Example #13
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the name column
 *
 * @return name column
 */
public AttributesColumn getNameColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_NAME);
}
 
Example #14
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the description column
 *
 * @return description column
 */
public AttributesColumn getDescriptionColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_DESCRIPTION);
}
 
Example #15
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the fill opacity column
 * 
 * @return fill opacity column
 */
public AttributesColumn getFillOpacityColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_FILL_OPACITY);
}
 
Example #16
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the fill color column
 * 
 * @return fill color column
 */
public AttributesColumn getFillColorColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_FILL_COLOR);
}
 
Example #17
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the width column
 * 
 * @return width column
 */
public AttributesColumn getWidthColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_WIDTH);
}
 
Example #18
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the opacity column
 * 
 * @return opacity column
 */
public AttributesColumn getOpacityColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_OPACITY);
}
 
Example #19
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the color column
 * 
 * @return color column
 */
public AttributesColumn getColorColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_COLOR);
}
 
Example #20
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the description column
 * 
 * @return description column
 */
public AttributesColumn getDescriptionColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_DESCRIPTION);
}
 
Example #21
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the name column
 * 
 * @return name column
 */
public AttributesColumn getNameColumn() {
	return getColumns().getColumn(StyleTable.COLUMN_NAME);
}
 
Example #22
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with columns.size() columns and must
 * include an integer id column
 * 
 * @param tableName
 *            table name
 * @param columns
 *            table columns to create
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTable(String tableName,
		List<AttributesColumn> columns, Collection<Constraint> constraints);
 
Example #23
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with columns.size() columns and must
 * include an integer id column
 * 
 * @param tableName
 *            table name
 * @param columns
 *            table columns to create
 * @return attributes table
 * @since 1.2.1
 */
public AttributesTable createAttributesTable(String tableName,
		List<AttributesColumn> columns);
 
Example #24
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column with the provided name and the provided additional
 * columns.
 * 
 * @param tableName
 *            table name
 * @param idColumnName
 *            id column name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints);
 
Example #25
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column with the provided name and the provided additional
 * columns.
 * 
 * @param tableName
 *            table name
 * @param idColumnName
 *            id column name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @return attributes table
 * @since 1.2.1
 */
public AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns);
 
Example #26
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column named "id" and the provided additional columns.
 * 
 * @param tableName
 *            table name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints);
 
Example #27
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the color column
 *
 * @return color column
 */
public AttributesColumn getColorColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_COLOR);
}
 
Example #28
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the opacity column
 *
 * @return opacity column
 */
public AttributesColumn getOpacityColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_OPACITY);
}
 
Example #29
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the width column
 *
 * @return width column
 */
public AttributesColumn getWidthColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_WIDTH);
}
 
Example #30
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the fill color column
 *
 * @return fill color column
 */
public AttributesColumn getFillColorColumn() {
    return getColumns().getColumn(StyleTable.COLUMN_FILL_COLOR);
}