Java Code Examples for mil.nga.geopackage.features.user.FeatureDao#count()
The following examples show how to use
mil.nga.geopackage.features.user.FeatureDao#count() .
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: IndexerTask.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * 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 2
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * Test a transaction using shortcut methods * * @param featureDao feature dao * @param rows rows to insert * @param successful true for a successful transaction */ private void testUserDaoShortcuts2(FeatureDao featureDao, int rows, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { insertRows(featureDao, rows); } catch (Exception e) { featureDao.endTransaction(false); TestCase.fail(e.getMessage()); } finally { featureDao.endTransaction(successful); } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 3
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * Test a transaction with chunked inserts * * @param featureDao feature dao * @param rows rows to insert * @param chunkSize chunk size * @param successful true for a successful transaction */ private void testUserDaoChunks(FeatureDao featureDao, int rows, int chunkSize, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { for (int count = 1; count <= rows; count++) { insertRow(featureDao); if (count % chunkSize == 0) { if (successful) { featureDao.commit(); } else { featureDao.failTransaction(); featureDao.beginTransaction(); } } } } catch (Exception e) { featureDao.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { featureDao.endTransaction(); } else { featureDao.failTransaction(); } } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 4
Source File: FeaturePreviewUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test the GeoPackage draw feature preview * * @param activity activity * @param geoPackage GeoPackage * @throws IOException upon error */ public static void testDraw(Activity activity, GeoPackage geoPackage) throws IOException { for (String featureTable : geoPackage.getFeatureTables()) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); int count = featureDao.count( CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName()) + " IS NOT NULL"); BoundingBox contentsBoundingBox = geoPackage .getContentsBoundingBox(featureTable); BoundingBox indexedBoundingBox = geoPackage .getBoundingBox(featureTable); boolean expectImage = (contentsBoundingBox != null || indexedBoundingBox != null) && count > 0; boolean epsg = featureDao.getProjection().getAuthority() .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG); FeaturePreview preview = new FeaturePreview(activity, geoPackage, featureDao); Bitmap image = preview.draw(); if (epsg) { assertEquals(expectImage, image != null); } preview.setBufferPercentage(0.4); preview.setLimit((int) Math.ceil(count / 2.0)); Bitmap imageLimit = preview.draw(); if (epsg) { assertEquals(expectImage, imageLimit != null); } preview.setManual(true); preview.setBufferPercentage(0.05); preview.setLimit(null); FeatureTiles featureTiles = preview.getFeatureTiles(); featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setDensity( TileUtils.density(TileUtils.TILE_PIXELS_DEFAULT)); featureTiles.clearIconCache(); Bitmap imageManual = preview.draw(); if (epsg) { assertNotNull(imageManual); } preview.setBufferPercentage(0.35); preview.setLimit(Math.max(count - 1, 1)); Bitmap imageManualLimit = preview.draw(); if (epsg) { assertNotNull(imageManualLimit); } preview.setBufferPercentage(0.15); preview.setLimit(null); preview.appendWhere( CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > " + ((int) Math.floor(count / 2.0))); Bitmap imageManualWhere = preview.draw(); if (epsg) { assertNotNull(imageManualWhere); } if(image != null) { image.recycle(); } if(imageLimit != null) { imageLimit.recycle(); } if(imageManual != null) { imageManual.recycle(); } if(imageManualLimit != null) { imageManualLimit.recycle(); } if(imageManualWhere != null) { imageManualWhere.recycle(); } preview.close(); } }
Example 5
Source File: TransactionTest.java From geopackage-java with MIT License | 4 votes |
/** * Test a transaction with chunked inserts * * @param featureDao * feature dao * @param rows * rows to insert * @param chunkSize * chunk size * @param successful * true for a successful transaction */ private void testUserDaoChunks(FeatureDao featureDao, int rows, int chunkSize, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { for (int count = 1; count <= rows; count++) { insertRow(featureDao); if (count % chunkSize == 0) { if (successful) { featureDao.commit(); } else { featureDao.failTransaction(); featureDao.beginTransaction(); } } } } catch (Exception e) { featureDao.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { featureDao.endTransaction(); } else { featureDao.failTransaction(); } } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 6
Source File: FeaturePreviewUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test the GeoPackage draw feature preview * * @param geoPackage * GeoPackage * @throws IOException * upon error */ public static void testDraw(GeoPackage geoPackage) throws IOException { for (String featureTable : geoPackage.getFeatureTables()) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); int count = featureDao.count( CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName()) + " IS NOT NULL"); BoundingBox contentsBoundingBox = geoPackage .getContentsBoundingBox(featureTable); BoundingBox indexedBoundingBox = geoPackage .getBoundingBox(featureTable); boolean expectImage = (contentsBoundingBox != null || indexedBoundingBox != null) && count > 0; boolean epsg = featureDao.getProjection().getAuthority() .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG); FeaturePreview preview = new FeaturePreview(geoPackage, featureDao); BufferedImage image = preview.draw(); if (epsg) { assertEquals(expectImage, image != null); } if (writeImages) { ImageIO.write(image, "png", new File("image.png")); } preview.setBufferPercentage(0.4); preview.setLimit((int) Math.ceil(count / 2.0)); BufferedImage imageLimit = preview.draw(); if (epsg) { assertEquals(expectImage, imageLimit != null); } if (writeImages) { ImageIO.write(imageLimit, "png", new File("image_limit.png")); } preview.setManual(true); preview.setBufferPercentage(0.05); preview.setLimit(null); FeatureTiles featureTiles = preview.getFeatureTiles(); featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setScale( TileUtils.tileScale(TileUtils.TILE_PIXELS_DEFAULT)); featureTiles.clearIconCache(); BufferedImage imageManual = preview.draw(); if (epsg) { assertNotNull(imageManual); } if (writeImages) { ImageIO.write(imageManual, "png", new File("image_manual.png")); } preview.setBufferPercentage(0.35); preview.setLimit(Math.max(count - 1, 1)); BufferedImage imageManualLimit = preview.draw(); if (epsg) { assertNotNull(imageManualLimit); } if (writeImages) { ImageIO.write(imageManualLimit, "png", new File("image_manual_limit.png")); } preview.setBufferPercentage(0.15); preview.setLimit(null); preview.appendWhere( CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > " + ((int) Math.floor(count / 2.0))); BufferedImage imageManualWhere = preview.draw(); if (epsg) { assertNotNull(imageManualWhere); } if (writeImages) { ImageIO.write(imageManualWhere, "png", new File("image_manual_where.png")); System.out.println("Breakpoint here"); } } }
Example 7
Source File: TransactionTest.java From geopackage-android with MIT License | 3 votes |
/** * Test a transaction * * @param featureDao feature dao * @param rows rows to insert * @param successful true for a successful transaction */ private void testUserDao(FeatureDao featureDao, int rows, boolean successful) { int countBefore = featureDao.count(); SQLiteDatabase db = featureDao.getDatabaseConnection().getDb(); db.beginTransaction(); try { insertRows(featureDao, rows); if (successful) { db.setTransactionSuccessful(); } } catch (Exception e) { db.endTransaction(); TestCase.fail(e.getMessage()); } finally { db.endTransaction(); } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 8
Source File: TransactionTest.java From geopackage-android with MIT License | 3 votes |
/** * Test a transaction using shortcut methods * * @param featureDao feature dao * @param rows rows to insert * @param successful true for a successful transaction */ private void testUserDaoShortcuts(FeatureDao featureDao, int rows, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { insertRows(featureDao, rows); } catch (Exception e) { featureDao.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { featureDao.endTransaction(); } else { featureDao.failTransaction(); } } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 9
Source File: TransactionTest.java From geopackage-java with MIT License | 3 votes |
/** * Test a transaction * * @param featureDao * feature dao * @param rows * rows to insert * @param successful * true for a successful transaction * @throws SQLException * upon error */ private void testUserDao(FeatureDao featureDao, int rows, boolean successful) throws SQLException { int countBefore = featureDao.count(); Connection connection = featureDao.getConnection(); connection.setAutoCommit(false); try { insertRows(featureDao, rows); if (successful) { connection.commit(); } else { connection.rollback(); } } catch (Exception e) { connection.rollback(); TestCase.fail(e.getMessage()); } finally { connection.setAutoCommit(true); } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 10
Source File: TransactionTest.java From geopackage-java with MIT License | 3 votes |
/** * Test a transaction using shortcut methods * * @param featureDao * feature dao * @param rows * rows to insert * @param successful * true for a successful transaction */ private void testUserDaoShortcuts(FeatureDao featureDao, int rows, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { insertRows(featureDao, rows); } catch (Exception e) { featureDao.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { featureDao.endTransaction(); } else { featureDao.failTransaction(); } } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }
Example 11
Source File: TransactionTest.java From geopackage-java with MIT License | 3 votes |
/** * Test a transaction using shortcut methods * * @param featureDao * feature dao * @param rows * rows to insert * @param successful * true for a successful transaction */ private void testUserDaoShortcuts2(FeatureDao featureDao, int rows, boolean successful) { int countBefore = featureDao.count(); featureDao.beginTransaction(); try { insertRows(featureDao, rows); } catch (Exception e) { featureDao.endTransaction(false); TestCase.fail(e.getMessage()); } finally { featureDao.endTransaction(successful); } TestCase.assertEquals(successful ? countBefore + rows : countBefore, featureDao.count()); }