mil.nga.geopackage.io.GeoPackageIOUtils Java Examples
The following examples show how to use
mil.nga.geopackage.io.GeoPackageIOUtils.
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: GeoPackageManagerImpl.java From geopackage-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void exportGeoPackage(String database, Uri uri, ContentValues contentValues) throws IOException { // Get the GeoPackage database file File dbFile = getFile(database); // Insert the row ContentResolver resolver = context.getContentResolver(); Uri insertUri = resolver.insert(uri, contentValues); // Copy the GeoPackage file OutputStream outputStream = resolver.openOutputStream(insertUri); InputStream inputStream = new FileInputStream(dbFile); GeoPackageIOUtils.copyStream(inputStream, outputStream); }
Example #2
Source File: GeoPackageManagerImpl.java From geopackage-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean copy(String database, String databaseCopy) { // Copy the database as a new file File dbFile = getFile(database); File dbCopyFile = context.getDatabasePath(databaseCopy); try { GeoPackageIOUtils.copyFile(dbFile, dbCopyFile); } catch (IOException e) { throw new GeoPackageException( "Failed to copy GeoPackage database '" + database + "' to '" + databaseCopy + "'", e); } return exists(databaseCopy); }
Example #3
Source File: ImportCoverageDataTiffGeoPackageTestCase.java From geopackage-java with MIT License | 6 votes |
/** * Get the import coverage data tiff db file copied to the provided directory * * @param directory * @return */ private File copyImportCoverageDataTiffDbFile(File directory) { File file = TestUtils.getImportDbCoverageDataTiffFile(); File newFile = new File(directory, file.getName()); try { GeoPackageIOUtils.copyFile(file, newFile); } catch (IOException e) { throw new GeoPackageException( "Failed to copy GeoPackage to test directory. File: " + file.getAbsolutePath() + ", Test Directory: " + directory.getAbsolutePath(), e); } return newFile; }
Example #4
Source File: GeoPackageManagerTest.java From geopackage-java with MIT License | 6 votes |
/** * Test create attempt with no file extension * * @throws IOException */ @Test public void testCreateNoExtension() throws IOException { File testFolder = folder.newFolder(); File dbFile = new File(testFolder, TestConstants.TEST_DB_NAME); // Create assertTrue("Database failed to create", GeoPackageManager.create(dbFile)); assertTrue( "Database does not exist", GeoPackageIOUtils.addFileExtension(dbFile, GeoPackageConstants.EXTENSION).exists()); // Open GeoPackage geoPackage = GeoPackageManager.open(dbFile); assertNotNull("Failed to open database", geoPackage); geoPackage.close(); }
Example #5
Source File: TestSetupTeardown.java From geopackage-java with MIT License | 6 votes |
/** * Get the import db file copied to the provided directory * * @param directory * @return */ private static File copyImportDbFile(File directory) { File file = TestUtils.getImportDbFile(); File newFile = new File(directory, file.getName()); try { GeoPackageIOUtils.copyFile(file, newFile); } catch (IOException e) { throw new GeoPackageException( "Failed to copy GeoPackage to test directory. File: " + file.getAbsolutePath() + ", Test Directory: " + directory.getAbsolutePath(), e); } return newFile; }
Example #6
Source File: ShareTask.java From geopackage-mapcache-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override protected String doInBackground(Object... params) { File databaseFile = (File) params[0]; String database = (String) params[1]; // Copy the database to cache File cacheDirectory = getDatabaseCacheDirectory(); cacheDirectory.mkdir(); cacheFile = new File(cacheDirectory, database + "." + GeoPackageConstants.GEOPACKAGE_EXTENSION); try { GeoPackageIOUtils.copyFile(databaseFile, cacheFile); } catch (IOException e) { return e.getMessage(); } return null; }
Example #7
Source File: ImportCoverageDataGeoPackageTestCase.java From geopackage-java with MIT License | 6 votes |
/** * Get the import coverage data db file copied to the provided directory * * @param directory * @return */ private File copyImportCoverageDataDbFile(File directory) { File file = TestUtils.getImportDbCoverageDataFile(); File newFile = new File(directory, file.getName()); try { GeoPackageIOUtils.copyFile(file, newFile); } catch (IOException e) { throw new GeoPackageException( "Failed to copy GeoPackage to test directory. File: " + file.getAbsolutePath() + ", Test Directory: " + directory.getAbsolutePath(), e); } return newFile; }
Example #8
Source File: LoadGeoPackageTestCase.java From geopackage-java with MIT License | 6 votes |
/** * {@inheritDoc} * * @throws IOException * @throws SQLException */ @Override protected GeoPackage getGeoPackage() throws Exception { File testFolder = folder.newFolder(); File testFile = TestUtils.getTestFile(file); File newFile = new File(testFolder, testFile.getName()); try { GeoPackageIOUtils.copyFile(testFile, newFile); } catch (IOException e) { throw new GeoPackageException( "Failed to copy GeoPackage to test directory. File: " + testFile.getAbsolutePath() + ", Test Directory: " + testFolder.getAbsolutePath(), e); } // Open GeoPackage geoPackage = GeoPackageManager.open(newFile); if (geoPackage == null) { throw new GeoPackageException("Failed to open database"); } return geoPackage; }
Example #9
Source File: GeoPackageManagerImpl.java From geopackage-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public boolean createFile(File file) { // Get the database name String database = GeoPackageIOUtils.getFileNameWithoutExtension(file); // Create the GeoPackage boolean created = createFile(database, file); return created; }
Example #10
Source File: TestUtils.java From geopackage-java with MIT License | 5 votes |
/** * Get the bytes of the file * * @param fileName * file name * @return file bytes */ public static byte[] getTestFileBytes(String fileName) { try { return GeoPackageIOUtils.fileBytes(getTestFile(fileName)); } catch (IOException e) { throw new GeoPackageException("Failed to get test file bytes", e); } }
Example #11
Source File: TestUtils.java From geopackage-java with MIT License | 5 votes |
/** * Get the tile file bytes * * @return file bytes */ public static byte[] getTileBytes() { try { return GeoPackageIOUtils.fileBytes(getTileFile()); } catch (IOException e) { throw new GeoPackageException("Failed to get tile bytes", e); } }
Example #12
Source File: FeatureStylesUtils.java From geopackage-java with MIT License | 5 votes |
private static IconRow randomIcon() throws IOException { IconRow iconRow = new IconRow(); File iconImageFile = TestUtils .getTestFile(TestConstants.ICON_POINT_IMAGE); byte[] iconBytes = GeoPackageIOUtils.fileBytes(iconImageFile); BufferedImage iconImage = ImageUtils.getImage(iconBytes); iconRow.setData(iconBytes); iconRow.setContentType( "image/" + TestConstants.ICON_POINT_IMAGE_EXTENSION); if (Math.random() < .5) { iconRow.setName("Icon Name"); } if (Math.random() < .5) { iconRow.setDescription("Icon Description"); } if (Math.random() < .5) { iconRow.setWidth(Math.random() * iconImage.getWidth()); } if (Math.random() < .5) { iconRow.setHeight(Math.random() * iconImage.getHeight()); } if (Math.random() < .5) { iconRow.setAnchorU(Math.random()); } if (Math.random() < .5) { iconRow.setAnchorV(Math.random()); } return iconRow; }
Example #13
Source File: GeoPackageManager.java From geopackage-java with MIT License | 5 votes |
/** * 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 #14
Source File: GeoPackageManager.java From geopackage-java with MIT License | 5 votes |
/** * 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 #15
Source File: DownloadTask.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); // If the indeterminate progress dialog is still showing, swap to a // determinate horizontal bar if (progressDialog.isIndeterminate()) { String messageSuffix = "\n\n" + GeoPackageIOUtils.formatBytes(max); ProgressDialog newProgressDialog = createDownloadProgressDialog( database, url, this, messageSuffix); newProgressDialog .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); newProgressDialog.setIndeterminate(false); newProgressDialog.setMax(100); newProgressDialog.show(); progressDialog.dismiss(); progressDialog = newProgressDialog; } // Set the progress progressDialog.setProgress(progress[0]); }
Example #16
Source File: ImportTask.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); // If the indeterminate progress dialog is still showing, swap to a // determinate horizontal bar if (progressDialog.isIndeterminate()) { String messageSuffix = "\n\n" + GeoPackageIOUtils.formatBytes(max); ProgressDialog newProgressDialog = createImportProgressDialog( database, this, path, uri, messageSuffix); newProgressDialog .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); newProgressDialog.setIndeterminate(false); newProgressDialog.setMax(100); newProgressDialog.show(); progressDialog.dismiss(); progressDialog = newProgressDialog; } // Set the progress progressDialog.setProgress(progress[0]); }
Example #17
Source File: CacheUtils.java From mage-android with Apache License 2.0 | 5 votes |
/** * Copy the Uri to the cache directory in a background task * * @param context * @param uri * @param path bn */ public static void copyToCache(Context context, Uri uri, String path) { // Get a cache directory to write to File cacheDirectory = CacheUtils.getApplicationCacheDirectory(context); if (cacheDirectory != null) { // Get the Uri display name, which should be the file name with extension String name = MediaUtility.getDisplayName(context, uri, path); // If no extension, add a GeoPackage extension if(GeoPackageIOUtils.getFileExtension(new File(name)) == null){ name += "." + GeoPackageConstants.GEOPACKAGE_EXTENSION; } // Verify that the file is a cache file by its extension File cacheFile = new File(cacheDirectory, name); if (isCacheFile(cacheFile)) { if(cacheFile.exists()) { cacheFile.delete(); } String cacheName = MediaUtility.getFileNameWithoutExtension(cacheFile); CacheProvider.getInstance(context).removeCacheOverlay(cacheName); // Copy the file in a background task CopyCacheStreamTask task = new CopyCacheStreamTask(context, uri, cacheFile, cacheName); task.execute(); } } }
Example #18
Source File: GeoPackageManagerImpl.java From geopackage-android with MIT License | 5 votes |
/** * {@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 #19
Source File: GeoPackageManagerImpl.java From geopackage-android with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public String readableSize(String database) { long size = size(database); return GeoPackageIOUtils.formatBytes(size); }
Example #20
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createFeatureStyleExtension(GeoPackage geoPackage) throws IOException { List<StyleRow> styles = new ArrayList<>(); StyleRow style1 = new StyleRow(); style1.setName("Green"); style1.setDescription("Green Style"); style1.setColor(ColorConstants.GREEN); style1.setWidth(2.0); styles.add(style1); StyleRow style2 = new StyleRow(); style2.setName("Blue with Red Fill"); style2.setDescription("Blue with Red Fill Style"); style2.setColor(new Color(ColorConstants.BLUE)); style2.setFillColor(new Color(255, 0, 0, .4f)); styles.add(style2); StyleRow style3 = new StyleRow(); style3.setName("Orange"); style3.setDescription("Orange Style"); style3.setColor(new Color(0xFFA500)); style3.setWidth(6.5); styles.add(style3); StyleRow style4 = new StyleRow(); style4.setName("Violet with Yellow Fill"); style4.setDescription("Violet with Yellow Fill Style"); style4.setColor(new Color(138, 43, 226)); style4.setWidth(4.1); style4.setFillColor(new Color(new float[] { 61, .89f, .72f }, .3f)); styles.add(style4); List<IconRow> icons = new ArrayList<>(); IconRow icon1 = new IconRow(); icon1.setName("Building"); icon1.setDescription("Building Icon"); icon1.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("building.png"))); icon1.setContentType("image/png"); icon1.setWidth(32.0); icon1.setAnchorU(0.5); icon1.setAnchorV(1.0); icons.add(icon1); IconRow icon2 = new IconRow(); icon2.setName("College"); icon2.setDescription("College Icon"); icon2.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("college.png"))); icon2.setContentType("image/png"); icon2.setWidth(32.0); icon2.setHeight(44.0); icons.add(icon2); IconRow icon3 = new IconRow(); icon3.setName("Tractor"); icon3.setDescription("Tractor Icon"); icon3.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("tractor.png"))); icon3.setContentType("image/png"); icon3.setAnchorV(1.0); icons.add(icon3); createFeatureStylesGeometry1(geoPackage, styles, icons); createFeatureStylesGeometry2(geoPackage, styles, icons); }
Example #21
Source File: GeoPackageValidate.java From geopackage-core-java with MIT License | 2 votes |
/** * Check the file name extension to see if it is a GeoPackage * * @param name * GeoPackage file name * @return true if GeoPackage extension * @since 3.5.0 */ public static boolean hasGeoPackageExtension(String name) { String extension = GeoPackageIOUtils.getFileExtension(name); return isGeoPackageExtension(extension); }
Example #22
Source File: GeoPackageValidate.java From geopackage-core-java with MIT License | 2 votes |
/** * Check the file extension to see if it is a GeoPackage * * @param file * GeoPackage file * @return true if GeoPackage extension */ public static boolean hasGeoPackageExtension(File file) { String extension = GeoPackageIOUtils.getFileExtension(file); return isGeoPackageExtension(extension); }