Java Code Examples for mil.nga.geopackage.GeoPackageManager#open()

The following examples show how to use mil.nga.geopackage.GeoPackageManager#open() . 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: TestSetupTeardown.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set up the import database
 * 
 * @param activity
 * @param testContext
 * @return
 */
public static GeoPackage setUpImport(Activity activity, Context testContext) {

	GeoPackageManager manager = GeoPackageFactory.getManager(activity);

	// Delete
	manager.delete(TestConstants.IMPORT_DB_NAME);

	// Copy the test db file from assets to the internal storage
	TestUtils.copyAssetFileToInternalStorage(activity, testContext,
			TestConstants.IMPORT_DB_FILE_NAME);

	// Import
	String importLocation = TestUtils.getAssetFileInternalStorageLocation(
			activity, TestConstants.IMPORT_DB_FILE_NAME);
	manager.importGeoPackage(new File(importLocation));

	// Open
	GeoPackage geoPackage = manager.open(TestConstants.IMPORT_DB_NAME);
	if (geoPackage == null) {
		throw new GeoPackageException("Failed to open database");
	}

	return geoPackage;
}
 
Example 2
Source File: LoadGeoPackageTestCase.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @throws IOException
 * @throws SQLException
 */
@Override
protected GeoPackage getGeoPackage() throws Exception {
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Delete
    manager.delete(name);

    // Copy the test db file from assets to the internal storage
    TestUtils.copyAssetFileToInternalStorage(activity, testContext,
            file);

    // Import
    String importLocation = TestUtils.getAssetFileInternalStorageLocation(
            activity, file);
    manager.importGeoPackage(new File(importLocation));

    // Open
    GeoPackage geoPackage = manager.open(name);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }

    return geoPackage;
}
 
Example 3
Source File: ImportCoverageDataGeoPackageTestCase.java    From geopackage-android with MIT License 6 votes vote down vote up
@Override
protected GeoPackage getGeoPackage() throws Exception {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Delete
    manager.delete(TestConstants.IMPORT_COVERAGE_DATA_DB_NAME);

    // Copy the test db file from assets to the internal storage
    TestUtils.copyAssetFileToInternalStorage(activity, testContext,
            TestConstants.IMPORT_COVERAGE_DATA_DB_FILE_NAME);

    // Import
    String importLocation = TestUtils.getAssetFileInternalStorageLocation(
            activity, TestConstants.IMPORT_COVERAGE_DATA_DB_FILE_NAME);
    manager.importGeoPackage(new File(importLocation));

    // Open
    GeoPackage geoPackage = manager.open(TestConstants.IMPORT_COVERAGE_DATA_DB_NAME);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }

    return geoPackage;
}
 
Example 4
Source File: ImportCoverageDataTiffGeoPackageTestCase.java    From geopackage-android with MIT License 6 votes vote down vote up
@Override
protected GeoPackage getGeoPackage() throws Exception {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Delete
    manager.delete(TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_NAME);

    // Copy the test db file from assets to the internal storage
    TestUtils.copyAssetFileToInternalStorage(activity, testContext,
            TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_FILE_NAME);

    // Import
    String importLocation = TestUtils.getAssetFileInternalStorageLocation(
            activity, TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_FILE_NAME);
    manager.importGeoPackage(new File(importLocation));

    // Open
    GeoPackage geoPackage = manager.open(TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_NAME);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }

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

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Delete
    manager.delete(TestConstants.IMPORT_DB_NAME);

    // Copy the test db file from assets to the internal storage
    TestUtils.copyAssetFileToInternalStorage(activity, testContext,
            TestConstants.IMPORT_DB_FILE_NAME);

    // Import
    String importLocation = TestUtils.getAssetFileInternalStorageLocation(
            activity, TestConstants.IMPORT_DB_FILE_NAME);
    manager.importGeoPackage(new File(importLocation));

    // Open
    GeoPackage geoPackage = manager.open(TestConstants.IMPORT_DB_NAME);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }

    return geoPackage;
}
 
Example 6
Source File: IndexerTask.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Index features
 *
 * @param activity
 * @param callback
 * @param database
 * @param tableName
 * @param indexLocation
 */
public static void indexFeatures(Activity activity, IIndexerTask callback,
                                 String database, String tableName,
                                 FeatureIndexType indexLocation) {

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

    FeatureDao featureDao = geoPackage.getFeatureDao(tableName);

    FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao);
    indexer.setIndexLocation(indexLocation);

    ProgressDialog progressDialog = new ProgressDialog(activity);
    final IndexerTask indexTask = new IndexerTask(activity,
            callback, progressDialog, geoPackage, indexer);

    int max = featureDao.count();
    indexTask.setMax(max);
    indexer.setProgress(indexTask);

    progressDialog.setMessage(activity
            .getString(R.string.geopackage_table_index_features_index_title)
            + ": "
            + geoPackage.getName() + " - " + tableName);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setIndeterminate(false);
    progressDialog.setMax(max);
    progressDialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
            activity.getString(R.string.button_cancel_label),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    indexTask.cancel(true);
                }
            });

    indexTask.execute();
}
 
Example 7
Source File: GeoPackageExample.java    From geopackage-android 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, NameNotFoundException {

    create();

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

    TestCase.assertTrue(manager.delete(GEOPACKAGE_NAME));
}
 
Example 8
Source File: GeoPackageManagerTest.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test creating and deleting a database
 */
@Test
public void testCreateOpenDelete() {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Verify does not exist
    assertFalse("Database already exists",
            manager.exists(TestConstants.TEST_DB_NAME));
    assertFalse("Database already returned in the set", manager
            .databaseSet().contains(TestConstants.TEST_DB_NAME));

    // Create
    assertTrue("Database failed to create",
            manager.create(TestConstants.TEST_DB_NAME));
    assertTrue("Database does not exist",
            manager.exists(TestConstants.TEST_DB_NAME));
    assertTrue("Database not returned in the set", manager.databaseSet()
            .contains(TestConstants.TEST_DB_NAME));

    // Open
    GeoPackage geoPackage = manager.open(TestConstants.TEST_DB_NAME);
    assertNotNull("Failed to open database", geoPackage);
    geoPackage.close();

    // Open with inverse validation
    manager.setOpenHeaderValidation(!manager.isOpenHeaderValidation());
    manager.setOpenIntegrityValidation(!manager.isOpenIntegrityValidation());
    geoPackage = manager.open(TestConstants.TEST_DB_NAME);
    assertNotNull("Failed to open database", geoPackage);
    geoPackage.close();

    // Delete
    assertTrue("Database not deleted",
            manager.delete(TestConstants.TEST_DB_NAME));
    assertFalse("Database exists after delete",
            manager.exists(TestConstants.TEST_DB_NAME));
    assertFalse("Database returned in the set after delete", manager
            .databaseSet().contains(TestConstants.TEST_DB_NAME));
}
 
Example 9
Source File: GeoPackageManagerTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test creating a database GeoPackage file as an external link
 */
private void createExternal(int testCase) {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Verify does not exist
    assertFalse("Database already exists",
            manager.exists(TestConstants.IMPORT_DB_NAME));
    assertFalse("Database already returned in the set", manager
            .databaseSet().contains(TestConstants.IMPORT_DB_NAME));

    // Create
    File externalDirectory = activity.getExternalCacheDir();
    File createFile = new File(externalDirectory, TestConstants.IMPORT_DB_FILE_NAME);
    createFile.delete();
    createExternal(manager, externalDirectory, createFile, testCase);
    assertTrue("Database does not exist",
            manager.exists(TestConstants.IMPORT_DB_NAME));
    assertTrue("Database not returned in the set", manager.databaseSet()
            .contains(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validate(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validateHeader(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validateIntegrity(TestConstants.IMPORT_DB_NAME));

    // Open
    GeoPackage geoPackage = manager.open(TestConstants.IMPORT_DB_NAME);
    assertNotNull("Failed to open database", geoPackage);
    geoPackage.close();

    // Attempt to create again
    try {
        createExternal(manager, externalDirectory, createFile, testCase);
        fail("Creating database again did not cause exception");
    } catch (GeoPackageException e) {
        // expected
    }

    // Delete
    assertTrue("Database not deleted",
            manager.delete(TestConstants.IMPORT_DB_NAME));
    assertFalse("Database exists after delete",
            manager.exists(TestConstants.IMPORT_DB_NAME));
    assertFalse("Database returned in the set after delete", manager
            .databaseSet().contains(TestConstants.IMPORT_DB_NAME));
    assertTrue("Create file could not be deleted", createFile.delete());

    // Import and Open with inverse validation
    manager.setImportHeaderValidation(!manager.isImportHeaderValidation());
    manager.setImportIntegrityValidation(!manager.isImportIntegrityValidation());
    manager.setOpenHeaderValidation(!manager.isOpenHeaderValidation());
    manager.setOpenIntegrityValidation(!manager.isOpenIntegrityValidation());

    // Create
    createExternal(manager, externalDirectory, createFile, testCase);
    assertTrue("Database does not exist",
            manager.exists(TestConstants.IMPORT_DB_NAME));
    assertTrue("Database not returned in the set", manager.databaseSet()
            .contains(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validate(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validateHeader(TestConstants.IMPORT_DB_NAME));
    assertTrue(manager.validateIntegrity(TestConstants.IMPORT_DB_NAME));

    // Open
    geoPackage = manager.open(TestConstants.IMPORT_DB_NAME);
    assertNotNull("Failed to open database", geoPackage);
    geoPackage.close();

    // Delete
    assertTrue("Database not deleted",
            manager.delete(TestConstants.IMPORT_DB_NAME));
    assertFalse("Database exists after delete",
            manager.exists(TestConstants.IMPORT_DB_NAME));
    assertFalse("Database returned in the set after delete", manager
            .databaseSet().contains(TestConstants.IMPORT_DB_NAME));

    // Delete the file
    assertTrue("Create file could not be deleted", createFile.delete());

}
 
Example 10
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();

}
 
Example 11
Source File: TestSetupTeardown.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Set up the create database
 *
 * @param activity
 * @param testContext
 * @param features
 * @param allowEmptyFeatures
 * @param tiles
 * @return
 * @throws SQLException
 * @throws IOException
 * @parma name
 */
public static GeoPackage setUpCreate(Activity activity,
                                     Context testContext, String name, boolean features, boolean allowEmptyFeatures, boolean tiles)
        throws SQLException, IOException {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);

    // Delete
    manager.delete(name);

    // Create
    manager.create(name);

    // Open
    GeoPackage geoPackage = manager.open(name);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }

    TestCase.assertEquals("Application Id", geoPackage.getApplicationId(), GeoPackageConstants.APPLICATION_ID);
    TestCase.assertEquals("User Version", geoPackage.getUserVersion(), GeoPackageConstants.USER_VERSION);
    String userVersionString = String.valueOf(geoPackage.getUserVersion());
    String majorVersion = userVersionString.substring(0, userVersionString.length() - 4);
    String minorVersion = userVersionString.substring(userVersionString.length() - 4, userVersionString.length() - 2);
    String patchVersion = userVersionString.substring(userVersionString.length() - 2);
    TestCase.assertEquals("Major User Version", geoPackage.getUserVersionMajor(), Integer.valueOf(majorVersion).intValue());
    TestCase.assertEquals("Minor User Version", geoPackage.getUserVersionMinor(), Integer.valueOf(minorVersion).intValue());
    TestCase.assertEquals("Patch User Version", geoPackage.getUserVersionPatch(), Integer.valueOf(patchVersion).intValue());

    if (features) {
        setUpCreateFeatures(geoPackage, allowEmptyFeatures);
    }

    if (tiles) {
        setUpCreateTiles(testContext, geoPackage);
    }

    setUpCreateCommon(geoPackage);

    return geoPackage;
}
 
Example 12
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 13
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 14
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Load tiles from a URL
 *
 * @param activity
 * @param callback
 * @param active
 * @param database
 * @param tableName
 * @param tileUrl
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 * @param authority
 * @param code
 */
public static void loadTiles(Activity activity, ILoadTilesTask callback,
                             GeoPackageDatabases active, String database, String tableName,
                             String tileUrl, int minZoom, int maxZoom,
                             CompressFormat compressFormat, Integer compressQuality,
                             boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) {

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

    Projection projection = ProjectionFactory.getProjection(authority, code);
    BoundingBox bbox = transform(boundingBox, projection);

    TileGenerator tileGenerator = new UrlTileGenerator(activity, geoPackage,
            tableName, tileUrl, minZoom, maxZoom, bbox, projection);
    setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling);

    loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator);
}
 
Example 15
Source File: TestSetupTeardown.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Set up the create database
 * 
 * @param activity
 * @param testContext
 * @param features
 * @param allowEmptyFeatures
 * @param tiles
 * @return
 * @throws SQLException
 * @throws IOException
 */
public static GeoPackage setUpCreate(Activity activity,
		Context testContext, boolean features, boolean allowEmptyFeatures, boolean tiles)
		throws SQLException, IOException {

	GeoPackageManager manager = GeoPackageFactory.getManager(activity);

	// Delete
	manager.delete(TestConstants.TEST_DB_NAME);

	// Create
	manager.create(TestConstants.TEST_DB_NAME);

	// Open
	GeoPackage geoPackage = manager.open(TestConstants.TEST_DB_NAME);
	if (geoPackage == null) {
		throw new GeoPackageException("Failed to open database");
	}

	TestCase.assertEquals("Application Id", geoPackage.getApplicationId(), GeoPackageConstants.APPLICATION_ID);
	TestCase.assertEquals("User Version", geoPackage.getUserVersion(), GeoPackageConstants.USER_VERSION);
	String userVersionString = String.valueOf(geoPackage.getUserVersion());
	String majorVersion = userVersionString.substring(0, userVersionString.length() - 4);
	String minorVersion = userVersionString.substring(userVersionString.length() - 4, userVersionString.length() - 2);
	String patchVersion = userVersionString.substring(userVersionString.length() - 2);
	TestCase.assertEquals("Major User Version", geoPackage.getUserVersionMajor(), Integer.valueOf(majorVersion).intValue());
	TestCase.assertEquals("Minor User Version", geoPackage.getUserVersionMinor(), Integer.valueOf(minorVersion).intValue());
	TestCase.assertEquals("Patch User Version", geoPackage.getUserVersionPatch(), Integer.valueOf(patchVersion).intValue());

	if (features) {
		setUpCreateFeatures(geoPackage, allowEmptyFeatures);
	}

	if (tiles) {
		setUpCreateTiles(testContext, geoPackage);
	}

	setUpCreateCommon(geoPackage);

	return geoPackage;
}
 
Example 16
Source File: PropertiesManagerTest.java    From geopackage-android with MIT License 3 votes vote down vote up
private List<GeoPackage> createGeoPackages() throws Exception {

        GeoPackageManager manager = GeoPackageFactory.getManager(activity);

        List<GeoPackage> geoPackages = new ArrayList<>();

        List<String> geoPackageNames = createGeoPackageNames();

        for (String name : geoPackageNames) {
            GeoPackage geoPackage = manager.open(name);
            geoPackages.add(geoPackage);
        }

        return geoPackages;
    }
 
Example 17
Source File: GeoPackageExample.java    From geopackage-android with MIT License 3 votes vote down vote up
private static GeoPackage createGeoPackage(Context context) {

        GeoPackageManager manager = GeoPackageFactory.getManager(context);

        manager.delete(GEOPACKAGE_NAME);

        manager.create(GEOPACKAGE_NAME);

        GeoPackage geoPackage = manager.open(GEOPACKAGE_NAME);
        if (geoPackage == null) {
            throw new GeoPackageException("Failed to open database");
        }

        return geoPackage;
    }