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

The following examples show how to use mil.nga.geopackage.GeoPackageManager#delete() . 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: 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 5
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 6
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 7
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 8
Source File: LoadGeoPackageTestCase.java    From geopackage-android with MIT License 5 votes vote down vote up
@After
public void tearDown() throws Exception {

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

    // Delete
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    manager.delete(name);

}
 
Example 9
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 10
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 11
Source File: GeoPackageManagerTest.java    From geopackage-android with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    // Delete existing test databases
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    manager.delete(TestConstants.TEST_DB_NAME);
    manager.delete(TestConstants.IMPORT_DB_NAME);
    manager.delete(IMPORT_CORRUPT_DB_NAME);
}
 
Example 12
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 13
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 14
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 15
Source File: TileOverlayPreferenceActivity.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Delete the GeoPackage cache overlay
 * @param geoPackageCacheOverlay
 */
private void deleteGeoPackageCacheOverlay(GeoPackageCacheOverlay geoPackageCacheOverlay) {

    String database = geoPackageCacheOverlay.getName();

    // Get the GeoPackage file
    GeoPackageManager manager = GeoPackageFactory.getManager(getActivity());
    File path = manager.getFile(database);

    // Delete the cache from the GeoPackage manager
    manager.delete(database);

    // Attempt to delete the cache file if it is in the cache directory
    File pathDirectory = path.getParentFile();
    if(path.canWrite() && pathDirectory != null) {
        Map<StorageUtility.StorageType, File> storageLocations = StorageUtility.getWritableStorageLocations();
        for (File storageLocation : storageLocations.values()) {
            File root = new File(storageLocation, getString(R.string.overlay_cache_directory));
            if (root.equals(pathDirectory)) {
                path.delete();
                break;
            }
        }
    }

    // Check internal/external application storage
    File applicationCacheDirectory = CacheUtils.getApplicationCacheDirectory(getActivity());
    if (applicationCacheDirectory != null && applicationCacheDirectory.exists()) {
        for (File cache : applicationCacheDirectory.listFiles()) {
            if (cache.equals(path)) {
                path.delete();
                break;
            }
        }
    }

    if (path.getAbsolutePath().startsWith(String.format("%s/MAGE/geopackages", getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)))) {
        LayerHelper layerHelper = LayerHelper.getInstance(getActivity().getApplicationContext());

        try {
            String relativePath = path.getAbsolutePath().split(getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/")[1];
            Layer layer = layerHelper.getByRelativePath(relativePath);
            if (layer != null) {
                layer.setLoaded(false);
                layer.setDownloadId(null);
                layerHelper.update(layer);
            }
        } catch (LayerException e) {
            Log.e(LOG_NAME, "Error setting loaded to false for path " + path, e);
        }

        if (!path.delete()) {
            Log.e(LOG_NAME, "Error deleting geopackage file from filesystem for path " + path);
        }
    }
}
 
Example 16
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;
    }