mil.nga.geopackage.validate.GeoPackageValidate Java Examples

The following examples show how to use mil.nga.geopackage.validate.GeoPackageValidate. 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: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private static void exportGeoPackage(Context context) throws IOException {

        if (ContextCompat.checkSelfPermission(context,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

            GeoPackageManager manager = GeoPackageFactory.getManager(context);

            String name = GeoPackageValidate.addGeoPackageExtension(GEOPACKAGE_NAME + "-" + System.currentTimeMillis());
            manager.exportGeoPackage(GEOPACKAGE_NAME,
                    name,
                    Environment.DIRECTORY_DOCUMENTS,
                    MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL));

            String path = "/storage/emulated/0/Documents/" + name;
            Log.i(LOG_NAME, "Created: " + path);
            Log.i(LOG_NAME, "To copy GeoPackage, run: "
                    + "adb pull " + path + " " + GeoPackageValidate.addGeoPackageExtension(GEOPACKAGE_NAME));
        } else {
            Log.w(LOG_NAME,
                    "To export the GeoPackage, grant GeoPackageSDKTests Storage permission on the emulator or phone");
        }

    }
 
Example #2
Source File: GeoPackageManagerImpl.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean importGeoPackage(String name, File file, boolean override) {

    // Verify the file has the right extension
    GeoPackageValidate.validateGeoPackageExtension(file);

    // Use the provided name or the base file name as the database name
    String database;
    if (name != null) {
        database = name;
    } else {
        database = GeoPackageIOUtils.getFileNameWithoutExtension(file);
    }

    boolean success = false;
    try {
        FileInputStream geoPackageStream = new FileInputStream(file);
        success = importGeoPackage(database, override, geoPackageStream,
                null);
    } catch (FileNotFoundException e) {
        throw new GeoPackageException(
                "Failed read or write GeoPackage file '" + file
                        + "' to database: '" + database + "'", e);
    }

    return success;
}
 
Example #3
Source File: GeoPackageManagerImpl.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void exportGeoPackage(String database, String name, String relativePath, Uri uri) throws IOException {

    // Add the extension if not on the name
    name = GeoPackageValidate.addGeoPackageExtension(name);

    ContentValues contentValues = new ContentValues();
    contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name);
    contentValues.put(MediaStore.MediaColumns.MIME_TYPE, GeoPackageConstants.MEDIA_TYPE);
    contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativePath);

    exportGeoPackage(database, uri, contentValues);
}
 
Example #4
Source File: LandingActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Handle opening the file path that MAGE was launched with
 */
private void handleOpenFilePath() {

    File cacheFile = new File(openPath);

    // Handle GeoPackage files by linking them to their current location
    if (GeoPackageValidate.hasGeoPackageExtension(cacheFile)) {

        String cacheName = GeoPackageCacheUtils.importGeoPackage(this, cacheFile);
        if (cacheName != null) {
            CacheProvider.getInstance(getApplicationContext()).enableAndRefreshTileOverlays(cacheName);
        }
    }
}
 
Example #5
Source File: GeoPackageManager.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create a GeoPackage
 * 
 * @param file
 *            file
 * @return true if created
 */
public static boolean create(File file) {

	boolean created = false;

	// Validate or add the file extension
	if (GeoPackageIOUtils.hasFileExtension(file)) {
		GeoPackageValidate.validateGeoPackageExtension(file);
	} else {
		file = GeoPackageIOUtils.addFileExtension(file,
				GeoPackageConstants.EXTENSION);
	}

	if (file.exists()) {
		throw new GeoPackageException(
				"GeoPackage already exists: " + file.getAbsolutePath());
	} else {
		// Create the GeoPackage Connection
		GeoPackageConnection connection = connect(file);

		// Set the GeoPackage application id and user version
		connection.setApplicationId();
		connection.setUserVersion();

		// Create the minimum required tables
		GeoPackageTableCreator tableCreator = new GeoPackageTableCreator(
				connection);
		tableCreator.createRequired();

		connection.close();
		created = true;
	}

	return created;
}
 
Example #6
Source File: GeoPackageManager.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Open a GeoPackage
 * 
 * @param name
 *            GeoPackage name
 * @param file
 *            GeoPackage file
 * @param validate
 *            validate the GeoPackage
 * @return GeoPackage
 * @since 3.3.0
 */
public static GeoPackage open(String name, File file, boolean validate) {

	// Validate or add the file extension
	if (validate) {
		if (GeoPackageIOUtils.hasFileExtension(file)) {
			GeoPackageValidate.validateGeoPackageExtension(file);
		} else {
			file = GeoPackageIOUtils.addFileExtension(file,
					GeoPackageConstants.EXTENSION);
		}
	}

	// Create the GeoPackage Connection and table creator
	GeoPackageConnection connection = connect(file);
	GeoPackageTableCreator tableCreator = new GeoPackageTableCreator(
			connection);

	// Create a GeoPackage
	GeoPackage geoPackage = new GeoPackageImpl(name, file, connection,
			tableCreator);

	// Validate the GeoPackage has the minimum required tables
	if (validate) {
		try {
			GeoPackageValidate.validateMinimumTables(geoPackage);
		} catch (RuntimeException e) {
			geoPackage.close();
			throw e;
		}
	}

	return geoPackage;
}
 
Example #7
Source File: CacheUtils.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if the file is a cache file based upon its extension
 *
 * @param file potential cache file
 * @return true if a cache file
 */
public static boolean isCacheFile(File file) {
    return GeoPackageValidate.hasGeoPackageExtension(file);
}
 
Example #8
Source File: SQLExec.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Check if the SQLite database is a GeoPackage
 * 
 * @param database
 *            SQLite database
 * @return true if a GeoPackage
 */
public static boolean isGeoPackage(GeoPackage database) {
	return GeoPackageValidate.hasMinimumTables(database);
}