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

The following examples show how to use mil.nga.geopackage.GeoPackage#close() . 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: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Get table Contents object
 */
public Contents getTableContents(String gpName, String tableName) {
    GeoPackage geo = null;
    try{
        geo = manager.open(gpName);
        if(geo != null) {
            ContentsDao contentsDao = geo.getContentsDao();
            Contents contents = contentsDao.queryForId(tableName);
            return contents;
        }

    } catch (Exception e){

    } finally {
        if(geo !=  null){
            geo.close();
        }
    }
    return null;
}
 
Example 2
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Create feature table in the given geopackage
 */
public boolean createFeatureTable(String gpName, BoundingBox boundingBox, GeometryType geometryType, String tableName){
    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey(tableName,
            "geom"));
    geometryColumns.setGeometryType(geometryType);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    GeoPackage geoPackage = manager.open(gpName);
    try {
        GeometryColumns created = geoPackage.createFeatureTableWithMetadata(
                geometryColumns, boundingBox, ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        if(created != null) {
            return true;
        }
    } finally {
        geoPackage.close();
    }
    return false;
}
 
Example 3
Source File: GeoPackageManagerTest.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Test creating and opening a database
 * 
 * @throws IOException
 */
@Test
public void testCreateOpen() throws IOException {

	File testFolder = folder.newFolder();
	File dbFile = new File(testFolder, TestConstants.TEST_DB_FILE_NAME);

	// Create
	assertTrue("Database failed to create",
			GeoPackageManager.create(dbFile));
	assertTrue("Database does not exist", dbFile.exists());

	// Open
	GeoPackage geoPackage = GeoPackageManager.open(dbFile);
	assertNotNull("Failed to open database", geoPackage);
	geoPackage.close();

}
 
Example 4
Source File: TileReader.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Read the tiles in the directory into the GeoPackage file table
 * 
 * @param geoPackageFile
 *            GeoPackage file
 * @param tileTable
 *            tile table
 * @param directory
 *            input directory
 * @param imageFormat
 *            image format
 * @param tileType
 *            tile type
 * @param rawImage
 *            use raw image flag
 * @throws IOException
 *             upon failure
 * @throws SQLException
 *             upon failure
 */
public static void readTiles(File geoPackageFile, String tileTable,
		File directory, String imageFormat, TileFormatType tileType,
		boolean rawImage) throws IOException, SQLException {

	// If the GeoPackage does not exist create it
	if (!geoPackageFile.exists()) {
		if (!GeoPackageManager.create(geoPackageFile)) {
			throw new GeoPackageException(
					"Failed to create GeoPackage file: "
							+ geoPackageFile.getAbsolutePath());
		}
	}

	// Open the GeoPackage
	GeoPackage geoPackage = GeoPackageManager.open(geoPackageFile);
	try {
		readTiles(geoPackage, tileTable, directory, imageFormat, tileType,
				rawImage);
	} finally {
		geoPackage.close();
	}
}
 
Example 5
Source File: PropertiesManagerTest.java    From geopackage-java with MIT License 6 votes vote down vote up
private List<String> createGeoPackageFiles() throws Exception {

		List<String> geoPackageFiles = new ArrayList<>();

		File testFolder = folder.newFolder();
		for (int i = 0; i < GEOPACKAGE_COUNT; i++) {
			GeoPackage geoPackage = TestSetupTeardown.setUpCreate(testFolder,
					GEOPACKAGE_FILE_NAME + i, true, true, true);
			if (i < GEOPACKAGE_WITH_PROPERTIES_COUNT) {
				addProperties(geoPackage, i);
			}
			geoPackageFiles.add(geoPackage.getPath());
			geoPackage.close();
		}

		return geoPackageFiles;
	}
 
Example 6
Source File: TestSetupTeardown.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Tear down the import database
 * 
 * @param activity
 * @param geoPackage
 */
public static void tearDownImport(Activity activity, GeoPackage geoPackage) {

	// Close
	if (geoPackage != null) {
		geoPackage.close();
	}

	// Delete
	GeoPackageManager manager = GeoPackageFactory.getManager(activity);
	manager.delete(TestConstants.IMPORT_DB_NAME);
}
 
Example 7
Source File: SQLExec.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Execute the SQL on the database
 * 
 * @param databaseFile
 *            database file
 * @param sql
 *            SQL statement
 * @param maxRows
 *            max rows
 * @return results
 * @throws SQLException
 *             upon SQL error
 */
public static SQLExecResult executeSQL(File databaseFile, String sql,
		Integer maxRows) throws SQLException {

	SQLExecResult result = null;

	GeoPackage database = GeoPackageManager.open(databaseFile);
	try {
		result = executeSQL(database, sql, maxRows);
	} finally {
		database.close();
	}

	return result;
}
 
Example 8
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 *  Returns the list of feature tables for a geopackage
 */
public List<String> getFeatureTables(String database){
    GeoPackage geo = manager.open(database);
    if(geo != null) {
        List<String> features = geo.getFeatureTables();
        geo.close();
        return features;
    }
    return null;
}
 
Example 9
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Returns the list of tile tables for a geopackage
 */
public List<String> getTileTables(String database){
    GeoPackage geo = manager.open(database);
    if(geo != null) {
        List<String> tiles = geo.getTileTables();
        geo.close();
        return tiles;
    }
    return null;
}
 
Example 10
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Copy a layer by name
 */
public boolean copyLayer(String geoPackageName, String layerName, String newLayerName) {
    try {
        GeoPackage geo = manager.open(geoPackageName);
        if (geo != null) {
            geo.copyTable(layerName, newLayerName);
            geo.close();
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}
 
Example 11
Source File: TestSetupTeardown.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Tear down the import database
 * 
 * @param geoPackage
 */
public static void tearDownImport(GeoPackage geoPackage) {

	// Close
	if (geoPackage != null) {
		geoPackage.close();
	}

}
 
Example 12
Source File: GeoPackageManagerTest.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test opening a database
 * 
 * @throws IOException
 */
@Test
public void testOpen() throws IOException {

	File dbFile = TestUtils.getImportDbFile();

	assertTrue("Database does not exist", dbFile.exists());

	// Open
	GeoPackage geoPackage = GeoPackageManager.open(dbFile);
	assertNotNull("Failed to open database", geoPackage);
	geoPackage.close();
}
 
Example 13
Source File: TestSetupTeardown.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Tear down the import database
 *
 * @param activity
 * @param geoPackage
 */
public static void tearDownImport(Activity activity, GeoPackage geoPackage) {

    // Close
    if (geoPackage != null) {
        geoPackage.close();
    }

    // Delete
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    manager.delete(TestConstants.IMPORT_DB_NAME);
}
 
Example 14
Source File: TestSetupTeardown.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Tear down the create database
 *
 * @param activity
 * @param geoPackage
 */
public static void tearDownCreate(Activity activity, GeoPackage geoPackage) {

    // Close
    if (geoPackage != null) {
        geoPackage.close();
    }

    // Delete
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    manager.delete(TestConstants.TEST_DB_NAME);
}
 
Example 15
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test making the GeoPackage example
 * 
 * @throws SQLException
 *             upon error
 * @throws IOException
 *             upon error
 */
@Test
public void testExample() throws SQLException, IOException {

	create();

	File file = new File(GEOPACKAGE_FILE);

	GeoPackage geoPackage = GeoPackageManager.open(file);
	TestCase.assertNotNull(geoPackage);
	geoPackage.close();

	TestCase.assertTrue(file.delete());
}
 
Example 16
Source File: TestSetupTeardown.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Tear down the create database
 * 
 * @param activity
 * @param geoPackage
 */
public static void tearDownCreate(Activity activity, GeoPackage geoPackage) {

	// Close
	if (geoPackage != null) {
		geoPackage.close();
	}

	// Delete
	GeoPackageManager manager = GeoPackageFactory.getManager(activity);
	manager.delete(TestConstants.TEST_DB_NAME);
}
 
Example 17
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage example NGA extensions
 *
 * @throws SQLException upon error
 * @throws IOException  upon error
 */
@Test
public void testExampleNGAExtensions() throws SQLException, IOException, NameNotFoundException {

    create();

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    GeoPackage geoPackage = manager.open(GEOPACKAGE_NAME);

    validateExtensions(geoPackage, true);
    validateNGAExtensions(geoPackage, true);

    NGAExtensions.deleteExtensions(geoPackage);

    validateExtensions(geoPackage, true);
    validateNGAExtensions(geoPackage, false);

    geoPackage.close();

    TestCase.assertTrue(manager.delete(GEOPACKAGE_NAME));
}
 
Example 18
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage example NGA extensions
 * 
 * @throws SQLException
 *             upon error
 * @throws IOException
 *             upon error
 */
@Test
public void testExampleNGAExtensions() throws SQLException, IOException {

	create();

	File file = new File(GEOPACKAGE_FILE);

	GeoPackage geoPackage = GeoPackageManager.open(file);

	validateExtensions(geoPackage, true);
	validateNGAExtensions(geoPackage, true);

	NGAExtensions.deleteExtensions(geoPackage);

	validateExtensions(geoPackage, true);
	validateNGAExtensions(geoPackage, false);

	geoPackage.close();

	TestCase.assertTrue(file.delete());
}
 
Example 19
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage example extensions
 *
 * @throws SQLException upon error
 * @throws IOException  upon error
 */
@Test
public void testExampleExtensions() throws SQLException, IOException, NameNotFoundException {

    create();

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    GeoPackage geoPackage = manager.open(GEOPACKAGE_NAME);

    validateExtensions(geoPackage, true);
    validateNGAExtensions(geoPackage, true);

    GeoPackageExtensions.deleteExtensions(geoPackage);

    validateExtensions(geoPackage, false);
    validateNGAExtensions(geoPackage, false);

    geoPackage.close();

    TestCase.assertTrue(manager.delete(GEOPACKAGE_NAME));
}
 
Example 20
Source File: OAPIFeatureGeneratorTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test a WFS server and create a GeoPackage
 *
 * @param server      server url
 * @param collection  collection name
 * @param name        geoPackage and table name
 * @param limit       request limit
 * @param totalLimit  total limit
 * @param boundingBox bounding box
 * @param time        time
 * @param period      period or end time
 * @throws SQLException upon error
 */
private void testServer(String server, String collection, String name,
                        Integer limit, Integer totalLimit, BoundingBox boundingBox,
                        String time, String period) throws SQLException {

    GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(activity);

    geoPackageManager.delete(collection);

    geoPackageManager.create(collection);

    GeoPackage geoPackage = geoPackageManager.open(collection);

    OAPIFeatureGenerator generator = new OAPIFeatureGenerator(
            geoPackage, name, server, collection);
    generator.setLimit(limit);
    generator.setTotalLimit(totalLimit);
    generator.setBoundingBox(boundingBox);
    generator.setTime(time);
    generator.setPeriod(period);
    generator.setDownloadAttempts(3);

    int count = generator.generateFeatures();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), count);
    }

    FeatureDao featureDao = generator.getFeatureDao();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), featureDao.count());
    }

    FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao);
    indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
    indexer.index();
    indexer.close();

    BoundingBox dataBounds = geoPackage
            .getBoundingBox(featureDao.getTableName());
    Contents contents = featureDao.getContents();
    contents.setBoundingBox(dataBounds);
    geoPackage.getContentsDao().update(contents);

    geoPackage.close();

}