Java Code Examples for mil.nga.geopackage.GeoPackage#createFeatureTable()

The following examples show how to use mil.nga.geopackage.GeoPackage#createFeatureTable() . 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: TestUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
Example 2
Source File: TestUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
Example 3
Source File: TestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 * 
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return feature table
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
		Contents contents, String geometryColumn, GeometryType geometryType)
		throws SQLException {

	FeatureTable table = buildFeatureTable(contents.getTableName(),
			geometryColumn, geometryType);
	geoPackage.createFeatureTable(table);

	double random = Math.random();

	DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
	DataColumns dataColumns = new DataColumns();
	dataColumns.setContents(contents);
	dataColumns.setColumnName(TEST_INTEGER_COLUMN);
	dataColumns.setName(contents.getTableName());
	dataColumns.setTitle("TEST_TITLE");
	dataColumns.setDescription("TEST_DESCRIPTION");
	dataColumns.setMimeType("TEST_MIME_TYPE");

	if (random < (1.0 / 3.0)) {
		dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
	} else if (random < (2.0 / 3.0)) {
		dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
	} else {
		dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
	}

	dataColumnsDao.create(dataColumns);

	return table;
}
 
Example 4
Source File: GeometryColumnsUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

    SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();
    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    if (dao.isTableExists()) {

        // Get current count
        long count = dao.countOf();
        TestCase.assertEquals(count, dao.getFeatureTables().size());

        // Retrieve a random srs
        List<SpatialReferenceSystem> results = srsDao.queryForAll();
        SpatialReferenceSystem srs = null;
        if (!results.isEmpty()) {
            int random = (int) (Math.random() * results.size());
            srs = results.get(random);
        }

        // Create a new contents
        Contents contents = new Contents();
        contents.setTableName("test_contents");
        contents.setDataType(ContentsDataType.FEATURES);
        contents.setIdentifier("test_contents");
        contents.setDescription("");
        // contents.setLastChange(new Date());
        contents.setMinX(-180.0);
        contents.setMinY(-90.0);
        contents.setMaxX(180.0);
        contents.setMaxY(90.0);
        contents.setSrs(srs);

        // Create the feature table
        geoPackage.createFeatureTable(TestUtils.buildFeatureTable(
                contents.getTableName(), "geom", GeometryType.GEOMETRY));

        contentsDao.create(contents);

        String columnName = "TEST_COLUMN_NAME";
        GeometryType geometryType = GeometryType.POINT;
        byte z = 2;
        byte m = 2;

        // Create new geometry columns
        GeometryColumns geometryColumns = new GeometryColumns();
        geometryColumns.setContents(contents);
        geometryColumns.setColumnName(columnName);
        geometryColumns.setGeometryType(geometryType);
        geometryColumns.setSrs(contents.getSrs());
        geometryColumns.setZ(z);
        geometryColumns.setM(m);
        dao.create(geometryColumns);

        // Verify count
        long newCount = dao.countOf();
        TestCase.assertEquals(count + 1, newCount);
        TestCase.assertEquals(newCount, dao.getFeatureTables().size());
        TestCase.assertTrue(dao.getFeatureTables().contains(
                contents.getTableName()));

        // Verify saved geometry columns
        GeometryColumns queryGeometryColumns = dao
                .queryForId(geometryColumns.getId());
        TestCase.assertEquals(contents.getId(),
                queryGeometryColumns.getTableName());
        TestCase.assertEquals(columnName,
                queryGeometryColumns.getColumnName());
        TestCase.assertEquals(geometryType,
                queryGeometryColumns.getGeometryType());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrsId());
        TestCase.assertEquals(z, queryGeometryColumns.getZ());
        TestCase.assertEquals(m, queryGeometryColumns.getM());
        TestCase.assertEquals(contents.getId(), queryGeometryColumns
                .getContents().getId());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrs().getId());
    }
}
 
Example 5
Source File: GeometryColumnsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();
		TestCase.assertEquals(count, dao.getFeatureTables().size());

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.FEATURES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the feature table
		geoPackage.createFeatureTable(TestUtils.buildFeatureTable(
				contents.getTableName(), "geom", GeometryType.GEOMETRY));

		contentsDao.create(contents);

		String columnName = "TEST_COLUMN_NAME";
		GeometryType geometryType = GeometryType.POINT;
		byte z = 2;
		byte m = 2;

		// Create new geometry columns
		GeometryColumns geometryColumns = new GeometryColumns();
		geometryColumns.setContents(contents);
		geometryColumns.setColumnName(columnName);
		geometryColumns.setGeometryType(geometryType);
		geometryColumns.setSrs(contents.getSrs());
		geometryColumns.setZ(z);
		geometryColumns.setM(m);
		dao.create(geometryColumns);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);
		TestCase.assertEquals(newCount, dao.getFeatureTables().size());
		TestCase.assertTrue(dao.getFeatureTables().contains(
				contents.getTableName()));

		// Verify saved geometry columns
		GeometryColumns queryGeometryColumns = dao
				.queryForId(geometryColumns.getId());
		TestCase.assertEquals(contents.getId(),
				queryGeometryColumns.getTableName());
		TestCase.assertEquals(columnName,
				queryGeometryColumns.getColumnName());
		TestCase.assertEquals(geometryType,
				queryGeometryColumns.getGeometryType());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryGeometryColumns.getSrsId());
		TestCase.assertEquals(z, queryGeometryColumns.getZ());
		TestCase.assertEquals(m, queryGeometryColumns.getM());
		TestCase.assertEquals(contents.getId(), queryGeometryColumns
				.getContents().getId());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryGeometryColumns.getSrs().getId());
	}
}