Java Code Examples for mil.nga.geopackage.features.user.FeatureColumn

The following examples show how to use mil.nga.geopackage.features.user.FeatureColumn. These examples are extracted from open source projects. 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 Project: geopackage-android   Source File: AlterTableUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Index the column
 *
 * @param db        connection
 * @param tableName table name
 * @param column    feature column
 */
private static void indexColumn(GeoPackageConnection db, String tableName,
                                FeatureColumn column) {
    if (!column.isPrimaryKey() && !column.isGeometry()) {
        StringBuilder index = new StringBuilder(
                "CREATE INDEX IF NOT EXISTS ");
        index.append(CoreSQLUtils
                .quoteWrap("idx_" + tableName + "_" + column.getName()));
        index.append(" ON ");
        index.append(CoreSQLUtils.quoteWrap(tableName));
        index.append(" ( ");
        String columnName = column.getName();
        if (columnName.contains(" ")) {
            columnName = CoreSQLUtils.quoteWrap(columnName);
        }
        index.append(columnName);
        index.append(" )");

        db.execSQL(index.toString());
    }
}
 
Example 2
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and additional columns
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataAdditionalColumns(
        GeoPackage geoPackage) throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata3", "geom3"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    List<FeatureColumn> additionalColumns = getFeatureColumns();

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, additionalColumns, boundingBox, srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
            additionalColumns);
}
 
Example 3
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata, id column, and additional
 * columns
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumnAdditionalColumns(
        GeoPackage geoPackage) throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata4", "geom4"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    List<FeatureColumn> additionalColumns = getFeatureColumns();

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    String idColumn = "my_other_id";
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, idColumn, additionalColumns, boundingBox,
            srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
            additionalColumns);
}
 
Example 4
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Get additional feature columns to create
 *
 * @return
 */
public static List<FeatureColumn> getFeatureColumns() {
    List<FeatureColumn> columns = new ArrayList<FeatureColumn>();

    columns.add(FeatureColumn.createColumn(7, "test_text_limited",
            GeoPackageDataType.TEXT, 5L, false, null));
    columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
            GeoPackageDataType.BLOB, 7L, false, null));
    columns.add(FeatureColumn.createColumn(9, "test_date",
            GeoPackageDataType.DATE, false, null));
    columns.add(FeatureColumn.createColumn(10, "test_datetime",
            GeoPackageDataType.DATETIME, false, null));
    columns.add(FeatureColumn.createColumn(2, "test_text",
            GeoPackageDataType.TEXT, false, ""));
    columns.add(FeatureColumn.createColumn(3, "test_real",
            GeoPackageDataType.REAL, false, null));
    columns.add(FeatureColumn.createColumn(4, "test_boolean",
            GeoPackageDataType.BOOLEAN, false, null));
    columns.add(FeatureColumn.createColumn(5, "test_blob",
            GeoPackageDataType.BLOB, false, null));
    columns.add(FeatureColumn.createColumn(6, "test_integer",
            GeoPackageDataType.INTEGER, false, null));

    return columns;
}
 
Example 5
Source Project: geopackage-core-java   Source File: FeatureCoreGenerator.java    License: MIT License 6 votes vote down vote up
/**
 * Get the column, create if needed
 * 
 * @param column
 *            column name
 * @param value
 *            value
 * @return feature column
 */
protected FeatureColumn getColumn(String column, Object value) {

	FeatureColumn featureColumn = columns.get(column);

	if (featureColumn == null) {
		boolean inTransaction = geoPackage.inTransaction();
		if (inTransaction) {
			geoPackage.endTransaction();
		}
		try {
			featureColumn = createColumn(column, value);
			addColumn(featureColumn);
			columns.put(column, featureColumn);
		} finally {
			if (inTransaction) {
				geoPackage.beginTransaction();
			}
		}
	}

	return featureColumn;
}
 
Example 6
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, String idColumnName,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId) {

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

	List<FeatureColumn> columns = new ArrayList<FeatureColumn>();
	columns.add(FeatureColumn.createPrimaryKeyColumn(idColumnName));
	columns.add(FeatureColumn.createGeometryColumn(
			geometryColumns.getColumnName(),
			geometryColumns.getGeometryType()));

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

	return createFeatureTableWithMetadata(geometryColumns, boundingBox,
			srsId, columns);
}
 
Example 7
Source Project: geopackage-java   Source File: AlterTableUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Index the column
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param column
 *            feature column
 */
private static void indexColumn(GeoPackageConnection db, String tableName,
		FeatureColumn column) {
	if (!column.isPrimaryKey() && !column.isGeometry()) {
		StringBuilder index = new StringBuilder(
				"CREATE INDEX IF NOT EXISTS ");
		index.append(CoreSQLUtils
				.quoteWrap("idx_" + tableName + "_" + column.getName()));
		index.append(" ON ");
		index.append(CoreSQLUtils.quoteWrap(tableName));
		index.append(" ( ");
		String columnName = column.getName();
		if (columnName.contains(" ")) {
			columnName = CoreSQLUtils.quoteWrap(columnName);
		}
		index.append(columnName);
		index.append(" )");

		db.execSQL(index.toString());
	}
}
 
Example 8
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and additional columns
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataAdditionalColumns(
		GeoPackage geoPackage) throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	List<FeatureColumn> additionalColumns = getFeatureColumns();

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, additionalColumns, boundingBox, srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
			additionalColumns);
}
 
Example 9
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata, id column, and additional
 * columns
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumnAdditionalColumns(
		GeoPackage geoPackage) throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	List<FeatureColumn> additionalColumns = getFeatureColumns();

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	String idColumn = "my_other_id";
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, idColumn, additionalColumns, boundingBox,
			srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
			additionalColumns);
}
 
Example 10
Source Project: geopackage-android-map   Source File: TestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Build an example feature table
 *
 * @param tableName
 * @param geometryColumn
 * @param geometryType
 * @return
 */
public static FeatureTable buildFeatureTable(String tableName,
                                             String geometryColumn, GeometryType geometryType) {

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

    columns.add(FeatureColumn.createPrimaryKeyColumn(0, "id"));
    columns.add(FeatureColumn.createColumn(7, "test_text_limited",
            GeoPackageDataType.TEXT, 5L, false, null));
    columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
            GeoPackageDataType.BLOB, 7L, false, null));
    columns.add(FeatureColumn.createGeometryColumn(1, geometryColumn,
            geometryType, false, null));
    columns.add(FeatureColumn.createColumn(2, "test_text",
            GeoPackageDataType.TEXT, false, ""));
    columns.add(FeatureColumn.createColumn(3, "test_real",
            GeoPackageDataType.REAL, false, null));
    columns.add(FeatureColumn.createColumn(4, "test_boolean",
            GeoPackageDataType.BOOLEAN, false, null));
    columns.add(FeatureColumn.createColumn(5, "test_blob",
            GeoPackageDataType.BLOB, false, null));
    columns.add(FeatureColumn.createColumn(6, TEST_INTEGER_COLUMN,
            GeoPackageDataType.INTEGER, false, null));

    FeatureTable table = new FeatureTable(tableName, columns);

    return table;
}
 
Example 11
Source Project: geopackage-android   Source File: FeatureIndexManagerUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Test large index
 *
 * @param activity    activity
 * @param geoPackage  GeoPackage
 * @param numFeatures num features
 * @param verbose     verbose printing
 * @throws SQLException upon error
 */
public static void testLargeIndex(Activity activity, GeoPackage geoPackage, int numFeatures,
                                  boolean verbose) throws SQLException {

    String featureTable = "large_index";

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey(featureTable, "geom"));
    geometryColumns.setGeometryType(GeometryType.POLYGON);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-180, -90, 180, 90);

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
            .getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
                    ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    List<FeatureColumn> additionalColumns = GeoPackageTestUtils
            .getFeatureColumns();
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, additionalColumns, boundingBox, srs.getId());

    FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

    System.out.println();
    System.out.println("Inserting Feature Rows: " + numFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, geometryColumns,
            featureDao.getTable(), numFeatures, false, false, false);

    testTimedIndex(activity, geoPackage, featureTable, true, verbose);
}
 
Example 12
Source Project: geopackage-android   Source File: TestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Build an example feature table
 *
 * @param tableName
 * @param geometryColumn
 * @param geometryType
 * @return
 */
public static FeatureTable buildFeatureTable(String tableName,
                                             String geometryColumn, GeometryType geometryType) {

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

    columns.add(FeatureColumn.createPrimaryKeyColumn(0, "id"));
    columns.add(FeatureColumn.createColumn(7, "test_text_limited",
            GeoPackageDataType.TEXT, 5L));
    columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
            GeoPackageDataType.BLOB, 7L));
    columns.add(FeatureColumn.createColumn(9, "test_date",
            GeoPackageDataType.DATE));
    columns.add(FeatureColumn.createColumn(10, "test_datetime",
            GeoPackageDataType.DATETIME));
    columns.add(FeatureColumn.createGeometryColumn(1, geometryColumn,
            geometryType));
    columns.add(FeatureColumn.createColumn(2, "test_text",
            GeoPackageDataType.TEXT, false, ""));
    columns.add(FeatureColumn.createColumn(3, "test_real",
            GeoPackageDataType.REAL));
    columns.add(FeatureColumn.createColumn(4, "test_boolean",
            GeoPackageDataType.BOOLEAN));
    columns.add(FeatureColumn.createColumn(5, "test_blob",
            GeoPackageDataType.BLOB));
    columns.add(FeatureColumn.createColumn(6, TEST_INTEGER_COLUMN,
            GeoPackageDataType.INTEGER));

    FeatureTable table = new FeatureTable(tableName, geometryColumn, columns);

    return table;
}
 
Example 13
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId) {
	return createFeatureTableWithMetadata(geometryColumns, null,
			additionalColumns, boundingBox, srsId);
}
 
Example 14
Source Project: geopackage-java   Source File: FeatureIndexManagerUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Test large index
 *
 * @param geoPackage
 *            GeoPackage
 * @param numFeatures
 *            num features
 * @param verbose
 *            verbose printing
 * @throws SQLException
 *             upon error
 */
public static void testLargeIndex(GeoPackage geoPackage, int numFeatures,
		boolean verbose) throws SQLException {

	String featureTable = "large_index";

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey(featureTable, "geom"));
	geometryColumns.setGeometryType(GeometryType.POLYGON);
	geometryColumns.setZ((byte) 0);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-180, -90, 180, 90);

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
	List<FeatureColumn> additionalColumns = GeoPackageTestUtils
			.getFeatureColumns();
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, additionalColumns, boundingBox, srs.getId());

	FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

	System.out.println();
	System.out.println("Inserting Feature Rows: " + numFeatures);
	TestUtils.addRowsToFeatureTable(geoPackage, geometryColumns,
			featureDao.getTable(), numFeatures, false, false, false);

	testTimedIndex(geoPackage, featureTable, true, verbose);
}
 
Example 15
Source Project: geopackage-java   Source File: TestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Build an example feature table
 * 
 * @param tableName
 * @param geometryColumn
 * @param geometryType
 * @return feature table
 */
public static FeatureTable buildFeatureTable(String tableName,
		String geometryColumn, GeometryType geometryType) {

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

	columns.add(FeatureColumn.createPrimaryKeyColumn(0, "id"));
	columns.add(FeatureColumn.createColumn(7, "test_text_limited",
			GeoPackageDataType.TEXT, 5L));
	columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
			GeoPackageDataType.BLOB, 7L));
	columns.add(FeatureColumn.createColumn(9, "test_date",
			GeoPackageDataType.DATE));
	columns.add(FeatureColumn.createColumn(10, "test_datetime",
			GeoPackageDataType.DATETIME));
	columns.add(FeatureColumn.createGeometryColumn(1, geometryColumn,
			geometryType));
	columns.add(FeatureColumn.createColumn(2, "test_text",
			GeoPackageDataType.TEXT, false, ""));
	columns.add(FeatureColumn.createColumn(3, "test_real",
			GeoPackageDataType.REAL));
	columns.add(FeatureColumn.createColumn(4, "test_boolean",
			GeoPackageDataType.BOOLEAN));
	columns.add(FeatureColumn.createColumn(5, "test_blob",
			GeoPackageDataType.BLOB));
	columns.add(FeatureColumn.createColumn(6, TEST_INTEGER_COLUMN,
			GeoPackageDataType.INTEGER));

	FeatureTable table = new FeatureTable(tableName, geometryColumn,
			columns);

	return table;
}
 
Example 16
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Get additional feature columns to create
 * 
 * @return
 */
public static List<FeatureColumn> getFeatureColumns() {
	List<FeatureColumn> columns = new ArrayList<FeatureColumn>();

	columns.add(FeatureColumn.createColumn(7, "test_text_limited",
			GeoPackageDataType.TEXT, 5L));
	columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
			GeoPackageDataType.BLOB, 7L));
	columns.add(FeatureColumn.createColumn(9, "test_date",
			GeoPackageDataType.DATE));
	columns.add(FeatureColumn.createColumn(10, "test_datetime",
			GeoPackageDataType.DATETIME));
	columns.add(FeatureColumn.createColumn(2, "test_text",
			GeoPackageDataType.TEXT, false, ""));
	columns.add(FeatureColumn.createColumn(3, "test_real",
			GeoPackageDataType.REAL));
	columns.add(FeatureColumn.createColumn(4, "test_boolean",
			GeoPackageDataType.BOOLEAN));

	FeatureColumn blobColumn = FeatureColumn.createColumn("test_blob",
			GeoPackageDataType.BLOB);
	columns.add(blobColumn);
	// Let the index for this column be automatically set to 5
	// blobColumn.setIndex(5);

	// Test setting an index after column creation but before table creation
	FeatureColumn integerColumn = FeatureColumn.createColumn("test_integer",
			GeoPackageDataType.INTEGER);
	columns.add(integerColumn);
	integerColumn.setIndex(6);

	return columns;
}
 
Example 17
Source Project: geopackage-android   Source File: OAPIFeatureGenerator.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void addColumn(FeatureColumn featureColumn) {
    featureDao.addColumn(featureColumn);
}
 
Example 18
Source Project: geopackage-android   Source File: FeatureUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Validate a feature row
 *
 * @param columns
 * @param featureRow
 */
private static void validateFeatureRow(String[] columns,
                                       FeatureRow featureRow) {
    TestCase.assertEquals(columns.length, featureRow.columnCount());

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

        switch (rowType) {

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

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

            case Cursor.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 Cursor.FIELD_TYPE_BLOB:
                if (featureRow.getGeometryColumnIndex() == i) {
                    TestCase.assertTrue(value instanceof GeoPackageGeometryData);
                } else {
                    TestCase.assertTrue(value instanceof byte[]);
                }
                break;

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

        }
    }

    TestCase.assertTrue(featureRow.getId() >= 0);
}
 
Example 19
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 4 votes vote down vote up
/**
 * 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 20
Source Project: geopackage-java   Source File: OAPIFeatureGenerator.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void addColumn(FeatureColumn featureColumn) {
	featureDao.addColumn(featureColumn);
}
 
Example 21
Source Project: geopackage-java   Source File: FeatureUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Validate a feature row
 * 
 * @param columns
 * @param featureRow
 */
private static void validateFeatureRow(String[] columns,
		FeatureRow featureRow) {
	TestCase.assertEquals(columns.length, featureRow.columnCount());

	for (int i = 0; i < featureRow.columnCount(); i++) {
		FeatureColumn column = featureRow.getTable().getColumns().get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], featureRow.getColumnName(i));
		TestCase.assertEquals(i, featureRow.getColumnIndex(columns[i]));
		int rowType = featureRow.getRowColumnType(i);
		Object value = featureRow.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:
			if (featureRow.getGeometryColumnIndex() == i) {
				TestCase.assertTrue(value instanceof GeoPackageGeometryData);
			} else {
				TestCase.assertTrue(value instanceof byte[]);
			}
			break;

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

		}
	}

	TestCase.assertTrue(featureRow.getId() >= 0);
}
 
Example 22
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 4 votes vote down vote up
/**
 * 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 23
Source Project: geopackage-core-java   Source File: FeatureCoreGenerator.java    License: MIT License 3 votes vote down vote up
/**
 * Get the column value
 * 
 * @param column
 *            column name
 * @param value
 *            value
 * @return column value
 */
protected Object getValue(String column, Object value) {

	FeatureColumn featureColumn = getColumn(column, value);
	Object columnValue = getValue(value, featureColumn.getDataType());

	return columnValue;
}
 
Example 24
Source Project: geopackage-core-java   Source File: FeatureCoreGenerator.java    License: MIT License 2 votes vote down vote up
/**
 * Get the columns
 * 
 * @return columns
 */
public Map<String, FeatureColumn> getColumns() {
	return columns;
}
 
Example 25
Source Project: geopackage-core-java   Source File: FeatureCoreGenerator.java    License: MIT License 2 votes vote down vote up
/**
 * Add a new column
 * 
 * @param featureColumn
 *            feature column
 */
protected abstract void addColumn(FeatureColumn featureColumn);
 
Example 26
Source Project: geopackage-core-java   Source File: FeatureCoreGenerator.java    License: MIT License 2 votes vote down vote up
/**
 * Create a feature column
 * 
 * @param name
 *            column name
 * @param value
 *            value
 * @return feature column
 */
protected FeatureColumn createColumn(String name, Object value) {
	GeoPackageDataType type = getType(value);
	return FeatureColumn.createColumn(name, type);
}
 
Example 27
Source Project: geopackage-core-java   Source File: GeoPackageCore.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new feature table with GeoPackage metadata. Create the Geometry
 * Columns table if needed, create a user feature table, create a new
 * Contents, insert the new Geometry Columns.
 * 
 * The user feature table will be created with 2 + additionalColumns.size()
 * columns, an id column named "id", a geometry column using
 * {@link GeometryColumns#getColumnName()}, and the provided additional
 * columns.
 * 
 * @param geometryColumns
 *            geometry columns to create
 * @param additionalColumns
 *            additional user feature table columns to create in addition to
 *            id and geometry columns
 * @param boundingBox
 *            contents bounding box
 * @param srsId
 *            spatial reference system id
 * @return geometry columns
 * @since 1.1.1
 */
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId);
 
Example 28
Source Project: geopackage-core-java   Source File: GeoPackageCore.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new feature table with GeoPackage metadata. Create the Geometry
 * Columns table if needed, create a user feature table, create a new
 * Contents, insert the new Geometry Columns.
 * 
 * The user feature table will be created with 2 + additionalColumns.size()
 * columns, an id column with the provided name, a geometry column using
 * {@link GeometryColumns#getColumnName()}, and the provided additional
 * columns.
 * 
 * @param geometryColumns
 *            geometry columns to create
 * @param idColumnName
 *            id column name
 * @param additionalColumns
 *            additional user feature table columns to create in addition to
 *            id and geometry columns
 * @param boundingBox
 *            contents bounding box
 * @param srsId
 *            spatial reference system id
 * @return geometry columns
 * @since 1.1.1
 */
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, String idColumnName,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId);
 
Example 29
Source Project: geopackage-core-java   Source File: GeoPackageCore.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new feature table with GeoPackage metadata. Create the Geometry
 * Columns table if needed, create a user feature table, create a new
 * Contents, insert the new Geometry Columns.
 * 
 * The user feature table will be created using only the provided columns.
 * These should include the id column and the geometry column defined in
 * {@link GeometryColumns#getColumnName()}
 * 
 * @param geometryColumns
 *            geometry columns to create
 * @param boundingBox
 *            contents bounding box
 * @param srsId
 *            spatial reference system id
 * @param columns
 *            user feature table columns to create
 * @return geometry columns
 * @since 1.1.1
 */
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, BoundingBox boundingBox,
		long srsId, List<FeatureColumn> columns);