mil.nga.geopackage.core.contents.ContentsDataType Java Examples

The following examples show how to use mil.nga.geopackage.core.contents.ContentsDataType. 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: GeometryColumnsSfSql.java    From geopackage-core-java with MIT License 6 votes vote down vote up
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ GeometryColumnsSfSql.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.FEATURES.getName());
		}
		fTableName = contents.getId();
	}
}
 
Example #2
Source File: GeometryColumnsSqlMm.java    From geopackage-core-java with MIT License 6 votes vote down vote up
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ GeometryColumnsSqlMm.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.FEATURES.getName());
		}
		tableName = contents.getId();
	}
}
 
Example #3
Source File: GeometryColumns.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Set the contents
 * 
 * @param contents
 *            contents
 */
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException(
					"The " + Contents.class.getSimpleName() + " of a "
							+ GeometryColumns.class.getSimpleName()
							+ " must have a data type of "
							+ ContentsDataType.FEATURES.getName());
		}
		tableName = contents.getId();
	} else {
		tableName = null;
	}
}
 
Example #4
Source File: GeoPackageImpl.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(Contents contents) {

	if (contents == null) {
		throw new GeoPackageException("Non null "
				+ Contents.class.getSimpleName() + " is required to create "
				+ AttributesDao.class.getSimpleName());
	}
	if (contents.getDataType() != ContentsDataType.ATTRIBUTES) {
		throw new GeoPackageException(Contents.class.getSimpleName()
				+ " is required to be of type "
				+ ContentsDataType.ATTRIBUTES + ". Actual: "
				+ contents.getDataTypeString());
	}

	// Read the existing table and create the dao
	AttributesTableReader tableReader = new AttributesTableReader(
			contents.getTableName());
	final AttributesTable attributesTable = tableReader.readTable(database);
	attributesTable.setContents(contents);
	AttributesDao dao = new AttributesDao(getName(), database,
			attributesTable);

	return dao;
}
 
Example #5
Source File: TileMatrixSet.java    From geopackage-core-java with MIT License 6 votes vote down vote up
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a tiles data type (Spec Requirement 33)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null
				|| (dataType != ContentsDataType.TILES && dataType != ContentsDataType.GRIDDED_COVERAGE)) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ TileMatrixSet.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.TILES.getName() + " or "
					+ ContentsDataType.GRIDDED_COVERAGE.getName());
		}
		tableName = contents.getId();
	} else {
		tableName = null;
	}
}
 
Example #6
Source File: TileMatrix.java    From geopackage-core-java with MIT License 6 votes vote down vote up
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a tiles data type (Spec Requirement 42)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null
				|| (dataType != ContentsDataType.TILES && dataType != ContentsDataType.GRIDDED_COVERAGE)) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ TileMatrix.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.TILES.getName() + " or "
					+ ContentsDataType.GRIDDED_COVERAGE.getName());
		}
		tableName = contents.getId();
	} else {
		tableName = null;
	}
}
 
Example #7
Source File: GeoPackageImpl.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create "
                + AttributesDao.class.getSimpleName());
    }
    if (contents.getDataType() != ContentsDataType.ATTRIBUTES) {
        throw new GeoPackageException(Contents.class.getSimpleName()
                + " is required to be of type "
                + ContentsDataType.ATTRIBUTES + ". Actual: "
                + contents.getDataTypeString());
    }

    // Read the existing table and create the dao
    AttributesTableReader tableReader = new AttributesTableReader(
            contents.getTableName());
    final AttributesTable attributesTable = tableReader.readTable(database);
    attributesTable.setContents(contents);
    AttributesDao dao = new AttributesDao(getName(), database,
            attributesTable);

    // Register the table name (with and without quotes) to wrap cursors with the attributes cursor
    registerCursorWrapper(attributesTable.getTableName(),
            new GeoPackageCursorWrapper() {

                @Override
                public Cursor wrapCursor(Cursor cursor) {
                    return new AttributesCursor(attributesTable, cursor);
                }
            });

    return dao;
}
 
Example #8
Source File: AttributesTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void validateContents(Contents contents) {
	// Verify the Contents have an attributes data type
	ContentsDataType dataType = contents.getDataType();
	if (dataType == null || dataType != ContentsDataType.ATTRIBUTES) {
		throw new GeoPackageException(
				"The " + Contents.class.getSimpleName() + " of a "
						+ AttributesTable.class.getSimpleName()
						+ " must have a data type of "
						+ ContentsDataType.ATTRIBUTES.getName());
	}
}
 
Example #9
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isFeatureOrTileTable(String table) {
	boolean isType = false;
	Contents contents = getTableContents(table);
	if (contents != null) {
		ContentsDataType dataType = contents.getDataType();
		isType = dataType != null && (dataType == ContentsDataType.FEATURES
				|| dataType == ContentsDataType.TILES);
	}
	return isType;
}
 
Example #10
Source File: FeatureTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void validateContents(Contents contents) {
	// Verify the Contents have a features data type
	ContentsDataType dataType = contents.getDataType();
	if (dataType == null || dataType != ContentsDataType.FEATURES) {
		throw new GeoPackageException(
				"The " + Contents.class.getSimpleName() + " of a "
						+ FeatureTable.class.getSimpleName()
						+ " must have a data type of "
						+ ContentsDataType.FEATURES.getName());
	}
}
 
Example #11
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ContentsDataType getTableDataType(String table) {
	ContentsDataType tableType = null;
	Contents contents = getTableContents(table);
	if (contents != null) {
		tableType = contents.getDataType();
	}
	return tableType;
}
 
Example #12
Source File: GeoPackageExtensions.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Delete the Gridded Coverage extension
 * 
 * @param geoPackage
 *            GeoPackage
 * @since 3.2.0
 */
public static void deleteGriddedCoverageExtension(
		GeoPackageCore geoPackage) {

	List<String> coverageTables = geoPackage
			.getTables(ContentsDataType.GRIDDED_COVERAGE);
	for (String table : coverageTables) {
		geoPackage.deleteTable(table);
	}

	GriddedTileDao griddedTileDao = geoPackage.getGriddedTileDao();
	GriddedCoverageDao griddedCoverageDao = geoPackage
			.getGriddedCoverageDao();
	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

	try {
		if (griddedTileDao.isTableExists()) {
			geoPackage.dropTable(griddedTileDao.getTableName());
		}
		if (griddedCoverageDao.isTableExists()) {
			geoPackage.dropTable(griddedCoverageDao.getTableName());
		}
		if (extensionsDao.isTableExists()) {
			extensionsDao
					.deleteByExtension(CoverageDataCore.EXTENSION_NAME);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Gridded Coverage extension and tables. GeoPackage: "
						+ geoPackage.getName(),
				e);
	}

}
 
Example #13
Source File: GeoPackageExtensions.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Delete the Gridded Coverage extensions for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @since 3.2.0
 */
public static void deleteGriddedCoverage(GeoPackageCore geoPackage,
		String table) {

	if (geoPackage.isTableType(ContentsDataType.GRIDDED_COVERAGE, table)) {

		GriddedTileDao griddedTileDao = geoPackage.getGriddedTileDao();
		GriddedCoverageDao griddedCoverageDao = geoPackage
				.getGriddedCoverageDao();
		ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

		try {
			if (griddedTileDao.isTableExists()) {
				griddedTileDao.delete(table);
			}
			if (griddedCoverageDao.isTableExists()) {
				griddedCoverageDao.delete(table);
			}
			if (extensionsDao.isTableExists()) {
				extensionsDao.deleteByExtension(
						CoverageDataCore.EXTENSION_NAME, table);
			}
		} catch (SQLException e) {
			throw new GeoPackageException(
					"Failed to delete Table Index. GeoPackage: "
							+ geoPackage.getName() + ", Table: " + table,
					e);
		}
	}

}
 
Example #14
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileMatrixSet createTileTableWithMetadata(String tableName,
		BoundingBox contentsBoundingBox, long contentsSrsId,
		BoundingBox tileMatrixSetBoundingBox, long tileMatrixSetSrsId) {
	return createTileTableWithMetadata(ContentsDataType.TILES, tableName,
			contentsBoundingBox, contentsSrsId, tileMatrixSetBoundingBox,
			tileMatrixSetSrsId);
}
 
Example #15
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Copy the table
 * 
 * @param tableName
 *            table name
 * @param newTableName
 *            new table name
 * @param transferContent
 *            transfer content flag
 * @param extensions
 *            extensions copy flag
 */
protected void copyTable(String tableName, String newTableName,
		boolean transferContent, boolean extensions) {

	ContentsDataType dataType = getTableDataType(tableName);
	if (dataType != null) {
		switch (dataType) {

		case ATTRIBUTES:
			copyAttributeTable(tableName, newTableName, transferContent);
			break;

		case FEATURES:
			copyFeatureTable(tableName, newTableName, transferContent);
			break;

		case TILES:
		case GRIDDED_COVERAGE:
			copyTileTable(tableName, newTableName, transferContent);
			break;

		default:
			throw new GeoPackageException(
					"Unsupported data type: " + dataType);
		}
	} else {
		copyUserTable(tableName, newTableName, transferContent, false);
	}

	// Copy extensions
	if (extensions) {
		GeoPackageExtensions.copyTableExtensions(this, tableName,
				newTableName);
	}
}
 
Example #16
Source File: TileTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void validateContents(Contents contents) {
	// Verify the Contents have a tiles data type
	ContentsDataType dataType = contents.getDataType();
	if (dataType == null || (dataType != ContentsDataType.TILES
			&& dataType != ContentsDataType.GRIDDED_COVERAGE)) {
		throw new GeoPackageException(
				"The " + Contents.class.getSimpleName() + " of a "
						+ TileTable.class.getSimpleName()
						+ " must have a data type of "
						+ ContentsDataType.TILES.getName() + " or "
						+ ContentsDataType.GRIDDED_COVERAGE.getName());
	}
}
 
Example #17
Source File: TileTable.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getDataType() {
	return ContentsDataType.TILES.getName();
}
 
Example #18
Source File: SQLExec.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Print the command prompt help
 * 
 * @param database
 *            database
 */
private static void printHelp(GeoPackage database) {

	boolean isGeoPackage = isGeoPackage(database);

	System.out.println();
	System.out.println("- Supports most SQLite statements including:");
	System.out.println(
			"\tSELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, PRAGMA, VACUUM, etc");
	System.out.println("- Terminate SQL statements with a ;");
	System.out.println("- Exit with a single empty line");
	System.out.println();
	System.out.println("Commands:");
	System.out.println();
	System.out.println("\t" + COMMAND_HELP
			+ "              - print this help information");
	System.out.println("\t" + COMMAND_TABLES
			+ " [name]     - list database tables (all or LIKE table name)");
	System.out.println("\t" + COMMAND_INDEXES
			+ " [name]    - list database indexes (all or LIKE index name)");
	System.out.println("\t" + COMMAND_VIEWS
			+ " [name]      - list database views (all or LIKE view name)");
	System.out.println("\t" + COMMAND_TRIGGERS
			+ " [name]   - list database triggers (all or LIKE trigger name)");
	System.out.println("\t" + COMMAND_MAX_ROWS
			+ " n            - set the max rows per query to n");
	System.out.println("\t" + COMMAND_HISTORY
			+ "           - list successfully executed sql commands");
	System.out.println("\t" + COMMAND_PREVIOUS
			+ "                - re-execute the previous successful sql command");
	System.out.println(
			"\t!n                - re-execute a sql statement by history id n");
	System.out.println(
			"\t!-n               - re-execute a sql statement n commands back in history");
	System.out.println("\t" + COMMAND_WRITE_BLOBS + " [" + ARGUMENT_PREFIX
			+ BLOBS_ARGUMENT_EXTENSION + " file_extension] ["
			+ ARGUMENT_PREFIX + BLOBS_ARGUMENT_DIRECTORY + " directory] ["
			+ ARGUMENT_PREFIX + BLOBS_ARGUMENT_PATTERN + " pattern]");
	System.out.println(
			"\t                  - write blobs from the previous successful sql command to the file system");
	System.out.println(
			"\t                        ([directory]|blobs)/table_name/column_name/(pk_values|result_index|[pattern])[.file_extension]");
	System.out.println(
			"\t                     file_extension - file extension added to each saved blob file");
	System.out.println(
			"\t                     directory      - base directory to save table_name/column_name/blobs (default is ./"
					+ BLOBS_WRITE_DEFAULT_DIRECTORY + ")");
	System.out.println(
			"\t                     pattern        - file directory and/or name pattern consisting of column names in parentheses");
	System.out.println(
			"\t                                       (column_name)-(column_name2)");
	System.out.println(
			"\t                                       (column_name)/(column_name2)");
	System.out.println("\t" + COMMAND_TABLE_INFO
			+ " <name>       - PRAGMA table_info(<name>);");
	System.out.println("\t<name>            - SELECT * FROM <name>;");
	if (isGeoPackage) {
		System.out.println("\t" + COMMAND_CONTENTS
				+ " [name]   - List GeoPackage contents (all or LIKE table name)");
		System.out.println("\t" + ContentsDataType.ATTRIBUTES.getName()
				+ " [name] - List GeoPackage attributes tables (all or LIKE table name)");
		System.out.println("\t" + ContentsDataType.FEATURES.getName()
				+ " [name]   - List GeoPackage feature tables (all or LIKE table name)");
		System.out.println("\t" + ContentsDataType.TILES.getName()
				+ " [name]      - List GeoPackage tile tables (all or LIKE table name)");
		System.out.println("\t" + COMMAND_GEOPACKAGE_INFO
				+ " <name>      - Query GeoPackage metadata for the table name");
		System.out.println("\t" + COMMAND_EXTENSIONS
				+ " [name] - List GeoPackage extensions (all or LIKE table name)");
	}
	System.out.println();
	System.out.println("Special Supported Cases:");
	System.out.println();
	System.out.println("\tDrop Column  - Not natively supported in SQLite");
	System.out.println(
			"\t                  * ALTER TABLE table_name DROP column_name");
	System.out.println(
			"\t                  * ALTER TABLE table_name DROP COLUMN column_name");
	System.out.println("\tCopy Table   - Not a traditional SQL statment");
	System.out.println(
			"\t                  * ALTER TABLE table_name COPY TO new_table_name");
	if (isGeoPackage) {
		System.out.println(
				"\tRename Table - User tables are updated throughout the GeoPackage");
		System.out.println(
				"\t                  * ALTER TABLE table_name RENAME TO new_table_name");
		System.out.println(
				"\tDrop Table   - User tables are dropped throughout the GeoPackage");
		System.out.println("\t                  * DROP TABLE table_name");
	}
}
 
Example #19
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection, String table,
		boolean manual) {

	BoundingBox boundingBox = getContentsBoundingBox(projection, table);

	BoundingBox tableBoundingBox = null;
	String tableType = getTableType(table);
	ContentsDataType dataType = ContentsDataType.fromName(tableType);
	if (dataType != null) {
		switch (dataType) {
		case FEATURES:
			tableBoundingBox = getFeatureBoundingBox(projection, table,
					manual);
			break;
		case TILES:
		case GRIDDED_COVERAGE:
			try {
				TileMatrixSet tileMatrixSet = getTileMatrixSetDao()
						.queryForId(table);
				tableBoundingBox = tileMatrixSet.getBoundingBox(projection);
			} catch (SQLException e) {
				throw new GeoPackageException(
						"Failed to retrieve tile matrix set for table: "
								+ table,
						e);
			}
			break;
		default:

		}
	}

	if (tableBoundingBox != null) {
		if (boundingBox == null) {
			boundingBox = tableBoundingBox;
		} else {
			boundingBox = boundingBox.union(tableBoundingBox);
		}
	}

	return boundingBox;
}
 
Example #20
Source File: TestSetupTeardown.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Set up create for tiles test
 * 
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(GeoPackage geoPackage)
		throws SQLException, IOException {

	// Get existing SRS objects
	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();

	SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);

	TestCase.assertNotNull(epsgSrs);

	// Create the Tile Matrix Set and Tile Matrix tables
	geoPackage.createTileMatrixSetTable();
	geoPackage.createTileMatrixTable();

	// Create new Contents
	ContentsDao contentsDao = geoPackage.getContentsDao();

	Contents contents = new Contents();
	contents.setTableName("test_tiles");
	contents.setDataType(ContentsDataType.TILES);
	contents.setIdentifier("test_tiles");
	// contents.setDescription("");
	// contents.setLastChange(new Date());
	contents.setMinX(-180.0);
	contents.setMinY(-90.0);
	contents.setMaxX(180.0);
	contents.setMaxY(90.0);
	contents.setSrs(epsgSrs);

	// Create the user tile table
	TileTable tileTable = TestUtils.buildTileTable(contents.getTableName());
	geoPackage.createTileTable(tileTable);

	// Create the contents
	contentsDao.create(contents);

	// Create new Tile Matrix Set
	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	TileMatrixSet tileMatrixSet = new TileMatrixSet();
	tileMatrixSet.setContents(contents);
	tileMatrixSet.setSrs(contents.getSrs());
	tileMatrixSet.setMinX(contents.getMinX());
	tileMatrixSet.setMinY(contents.getMinY());
	tileMatrixSet.setMaxX(contents.getMaxX());
	tileMatrixSet.setMaxY(contents.getMaxY());
	tileMatrixSetDao.create(tileMatrixSet);

	// Create new Tile Matrix rows
	TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

	final int tileWidth = 256;
	final int tileHeight = 256;

	int matrixWidthAndHeight = 2;
	double pixelXSize = (tileMatrixSet.getMaxX() - tileMatrixSet.getMinX())
			/ (matrixWidthAndHeight * tileWidth);
	double pixelYSize = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY())
			/ (matrixWidthAndHeight * tileHeight);

	byte[] tileData = TestUtils.getTileBytes();

	for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) {

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidthAndHeight);
		tileMatrix.setMatrixHeight(matrixWidthAndHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		tileMatrixDao.create(tileMatrix);

		matrixWidthAndHeight *= 2;
		pixelXSize /= 2.0;
		pixelYSize /= 2.0;

		// Populate the tile table with rows
		TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData);
	}

}
 
Example #21
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());
	}
}
 
Example #22
Source File: TransactionTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 * 
 * @param geoPackage
 *            GeoPackage
 * @param successful
 *            true for a successful transaction
 * @throws SQLException
 *             upon error
 */
private void testORMLite(final GeoPackage geoPackage,
		final boolean successful) throws SQLException {

	final String tableName = "test_table";

	final Contents contents = new Contents();
	contents.setTableName(tableName);
	contents.setDataType(ContentsDataType.ATTRIBUTES);

	if (!geoPackage.isTable(tableName)) {
		geoPackage.execSQL("CREATE TABLE " + tableName
				+ " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
	}

	final SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	final ContentsDao contentsDao = geoPackage.getContentsDao();

	long srsCount = srsDao.countOf();
	long contentsCount = contentsDao.countOf();

	Callable<Void> callable = new Callable<Void>() {
		public Void call() throws Exception {

			SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

			contents.setSrs(srs);
			contentsDao.create(contents);

			if (!successful) {
				throw new SQLException();
			}

			return null;
		}
	};

	try {
		geoPackage.callInTransaction(callable);
	} catch (SQLException e) {
		if (successful) {
			TestCase.fail(e.getMessage());
		}
	}

	TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
			srsDao.countOf());
	TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
			contentsDao.countOf());

	TestCase.assertEquals(successful,
			geoPackage.isAttributeTable(tableName));

}
 
Example #23
Source File: TileMatrixUtils.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();
	TileMatrixDao dao = geoPackage.getTileMatrixDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();

		// 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.TILES);
		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 user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile
		int zoom = 3;
		int matrixWidth = 4;
		int matrixHeight = 5;
		int tileWidth = 128;
		int tileHeight = 256;
		double pixelXSize = 889.5;
		double pixelYSize = 900.1;

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidth);
		tileMatrix.setMatrixHeight(matrixHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		dao.create(tileMatrix);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved matrix tile
		TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrix.getTableName());
		TestCase.assertEquals(zoom, queryTileMatrix.getZoomLevel());
		TestCase.assertEquals(matrixWidth, queryTileMatrix.getMatrixWidth());
		TestCase.assertEquals(matrixHeight,
				queryTileMatrix.getMatrixHeight());
		TestCase.assertEquals(tileWidth, queryTileMatrix.getTileWidth());
		TestCase.assertEquals(tileHeight, queryTileMatrix.getTileHeight());
		TestCase.assertEquals(pixelXSize, queryTileMatrix.getPixelXSize());
		TestCase.assertEquals(pixelYSize, queryTileMatrix.getPixelYSize());
		TestCase.assertEquals(contents.getId(), queryTileMatrix
				.getContents().getId());
	}
}
 
Example #24
Source File: TileMatrixSetUtils.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();
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();
		TestCase.assertEquals(count, dao.getTileTables().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.TILES);
		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 user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile set
		TileMatrixSet tileMatrixSet = new TileMatrixSet();
		tileMatrixSet.setContents(contents);
		tileMatrixSet.setSrs(contents.getSrs());
		tileMatrixSet.setMinX(contents.getMinX());
		tileMatrixSet.setMinY(contents.getMinY());
		tileMatrixSet.setMaxX(contents.getMaxX());
		tileMatrixSet.setMaxY(contents.getMaxY());
		dao.create(tileMatrixSet);

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

		// Verify saved matrix tile set
		TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
				.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrixSet.getTableName());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrsId());
		TestCase.assertEquals(contents.getMinX(),
				queryTileMatrixSet.getMinX());
		TestCase.assertEquals(contents.getMinY(),
				queryTileMatrixSet.getMinY());
		TestCase.assertEquals(contents.getMaxX(),
				queryTileMatrixSet.getMaxX());
		TestCase.assertEquals(contents.getMaxY(),
				queryTileMatrixSet.getMaxY());
		TestCase.assertEquals(contents.getId(), queryTileMatrixSet
				.getContents().getId());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrs().getId());
	}
}
 
Example #25
Source File: TestSetupTeardown.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Set up create for tiles test
 * 
 * @param testContext
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(Context testContext,
		GeoPackage geoPackage) throws SQLException, IOException {

	// Get existing SRS objects
	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();

	SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);

	TestCase.assertNotNull(epsgSrs);

	// Create the Tile Matrix Set and Tile Matrix tables
	geoPackage.createTileMatrixSetTable();
	geoPackage.createTileMatrixTable();

	// Create new Contents
	ContentsDao contentsDao = geoPackage.getContentsDao();

	Contents contents = new Contents();
	contents.setTableName("test_tiles");
	contents.setDataType(ContentsDataType.TILES);
	contents.setIdentifier("test_tiles");
	// contents.setDescription("");
	// contents.setLastChange(new Date());
	contents.setMinX(-180.0);
	contents.setMinY(-90.0);
	contents.setMaxX(180.0);
	contents.setMaxY(90.0);
	contents.setSrs(epsgSrs);

	// Create the user tile table
	TileTable tileTable = TestUtils.buildTileTable(contents.getTableName());
	geoPackage.createTileTable(tileTable);

	// Create the contents
	contentsDao.create(contents);

	// Create new Tile Matrix Set
	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	TileMatrixSet tileMatrixSet = new TileMatrixSet();
	tileMatrixSet.setContents(contents);
	tileMatrixSet.setSrs(contents.getSrs());
	tileMatrixSet.setMinX(contents.getMinX());
	tileMatrixSet.setMinY(contents.getMinY());
	tileMatrixSet.setMaxX(contents.getMaxX());
	tileMatrixSet.setMaxY(contents.getMaxY());
	tileMatrixSetDao.create(tileMatrixSet);

	// Create new Tile Matrix rows
	TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

	int matrixWidthAndHeight = 2;
	double pixelXSize = 69237.2;
	double pixelYSize = 68412.1;

	// Read the asset tile to bytes and convert to bitmap
	byte[] assetTileData = TestUtils.getAssetFileBytes(testContext,
			TestConstants.TILE_FILE_NAME);
	Bitmap bitmap = BitmapConverter.toBitmap(assetTileData);

	// Get the width and height of the bitmap
	final int tileWidth = bitmap.getWidth();
	final int tileHeight = bitmap.getHeight();

	// Compress the bitmap back to bytes and use those for the test
	byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat
			.valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase()));

	for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) {

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidthAndHeight);
		tileMatrix.setMatrixHeight(matrixWidthAndHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		tileMatrixDao.create(tileMatrix);

		matrixWidthAndHeight *= 2;
		pixelXSize /= 2.0;
		pixelYSize /= 2.0;

		// Populate the tile table with rows
		TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData);
	}

}
 
Example #26
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test deleting tables by name
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteTables(GeoPackage geoPackage)
		throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();
	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();

	TestCase.assertTrue(geometryColumnsDao.isTableExists()
			|| tileMatrixSetDao.isTableExists());

	geoPackage.foreignKeys(false);

	if (geometryColumnsDao.isTableExists()) {

		TestCase.assertEquals(geoPackage.getFeatureTables().size(),
				geometryColumnsDao.countOf());
		for (String featureTable : geoPackage.getFeatureTables()) {
			TestCase.assertTrue(geoPackage.isTable(featureTable));
			TestCase.assertNotNull(contentsDao.queryForId(featureTable));
			geoPackage.deleteTable(featureTable);
			TestCase.assertFalse(geoPackage.isTable(featureTable));
			TestCase.assertNull(contentsDao.queryForId(featureTable));
		}
		TestCase.assertEquals(0, geometryColumnsDao.countOf());

		geoPackage.dropTable(GeometryColumns.TABLE_NAME);

		TestCase.assertFalse(geometryColumnsDao.isTableExists());
	}

	if (tileMatrixSetDao.isTableExists()) {
		TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

		TestCase.assertTrue(tileMatrixSetDao.isTableExists());
		TestCase.assertTrue(tileMatrixDao.isTableExists());

		TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES)
				.size()
				+ geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE)
						.size(),
				tileMatrixSetDao.countOf());
		for (String tileTable : geoPackage.getTileTables()) {
			TestCase.assertTrue(geoPackage.isTable(tileTable));
			TestCase.assertNotNull(contentsDao.queryForId(tileTable));
			geoPackage.deleteTable(tileTable);
			TestCase.assertFalse(geoPackage.isTable(tileTable));
			TestCase.assertNull(contentsDao.queryForId(tileTable));
		}
		TestCase.assertEquals(geoPackage
				.getTables(ContentsDataType.GRIDDED_COVERAGE).size(),
				tileMatrixSetDao.countOf());

		geoPackage.dropTable(TileMatrix.TABLE_NAME);
		geoPackage.dropTable(TileMatrixSet.TABLE_NAME);

		TestCase.assertFalse(tileMatrixSetDao.isTableExists());
		TestCase.assertFalse(tileMatrixDao.isTableExists());
	}

	for (String attributeTable : geoPackage.getAttributesTables()) {

		TestCase.assertTrue(geoPackage.isTable(attributeTable));
		TestCase.assertNotNull(contentsDao.queryForId(attributeTable));
		geoPackage.deleteTable(attributeTable);
		TestCase.assertFalse(geoPackage.isTable(attributeTable));
		TestCase.assertNull(contentsDao.queryForId(attributeTable));

	}

}
 
Example #27
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isTableType(ContentsDataType type, String table) {
	return isTableType(type.getName(), table);
}
 
Example #28
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isAttributeTable(String table) {
	return isTableType(ContentsDataType.ATTRIBUTES, table);
}
 
Example #29
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isTileTable(String table) {
	return isTableType(ContentsDataType.TILES, table);
}
 
Example #30
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isFeatureTable(String table) {
	return isTableType(ContentsDataType.FEATURES, table);
}