Java Code Examples for mil.nga.geopackage.GeoPackage#getFeatureDao()

The following examples show how to use mil.nga.geopackage.GeoPackage#getFeatureDao() . 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: FeatureTileUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create feature dao
 *
 * @return feature dao
 */
public static FeatureDao createFeatureDao(GeoPackage geoPackage) {

	BoundingBox boundingBox = new BoundingBox();

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey(TABLE_NAME, "geom"));
	geometryColumns.setGeometryType(GeometryType.GEOMETRY);
	geometryColumns.setZ((byte) 0);
	geometryColumns.setM((byte) 0);

	geoPackage.createFeatureTableWithMetadata(geometryColumns, boundingBox,
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

	FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

	return featureDao;
}
 
Example 2
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 3
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createGeometryIndexExtension(GeoPackage geoPackage) {

		List<String> featureTables = geoPackage.getFeatureTables();
		for (String featureTable : featureTables) {

			FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
			FeatureTableIndex featureTableIndex = new FeatureTableIndex(
					geoPackage, featureDao);
			featureTableIndex.index();
		}

	}
 
Example 4
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createGeometryIndexExtension(Context context, GeoPackage geoPackage) {

        List<String> featureTables = geoPackage.getFeatureTables();
        for (String featureTable : featureTables) {

            FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
            FeatureIndexManager indexer = new FeatureIndexManager(context, geoPackage, featureDao);
            indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
            indexer.index();
            indexer.close();
        }

    }
 
Example 5
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
		List<StyleRow> styles, List<IconRow> icons) throws IOException {

	FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
	FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
			featureDao.getTable());

	geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
	geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

	geometry2Styles.createStyleRelationship();
	geometry2Styles.createIconRelationship();

	FeatureResultSet features = featureDao.queryForAll();
	while (features.moveToNext()) {
		FeatureRow featureRow = features.getRow();
		switch (featureRow.getGeometryType()) {
		case POINT:
			geometry2Styles.setIcon(featureRow, icons.get(0));
			break;
		case LINESTRING:
			geometry2Styles.setStyle(featureRow, styles.get(0));
			break;
		case POLYGON:
			geometry2Styles.setStyle(featureRow, styles.get(1));
			break;
		default:
		}
	}
	features.close();

}
 
Example 6
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
    FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
    geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

    geometry2Styles.createStyleRelationship();
    geometry2Styles.createIconRelationship();

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                geometry2Styles.setIcon(featureRow, icons.get(0));
                break;
            case LINESTRING:
                geometry2Styles.setStyle(featureRow, styles.get(0));
                break;
            case POLYGON:
                geometry2Styles.setStyle(featureRow, styles.get(1));
                break;
            default:
        }
    }
    features.close();

}
 
Example 7
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
			TestCase.assertNotNull(dao);

			FeatureResultSet cursor = dao.queryForAll();
			int count = cursor.getCount();
			if (count > 0) {

				// Choose random feature
				int random = (int) (Math.random() * count);
				cursor.moveToPosition(random);

				FeatureRow featureRow = cursor.getRow();
				cursor.close();

				// Delete row
				TestCase.assertEquals(1, dao.delete(featureRow));

				// Verify deleted
				FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow
						.getId());
				TestCase.assertNull(queryFeatureRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}
	}
}
 
Example 8
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test transforming geometries between projections
 * 
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGeometryProjectionTransform(GeoPackage geoPackage)
		throws SQLException, IOException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
			TestCase.assertNotNull(dao);

			FeatureResultSet cursor = dao.queryForAll();

			while (cursor.moveToNext()) {

				GeoPackageGeometryData geometryData = cursor.getGeometry();
				if (geometryData != null) {

					Geometry geometry = geometryData.getGeometry();

					if (geometry != null) {

						SpatialReferenceSystemDao srsDao = geoPackage
								.getSpatialReferenceSystemDao();
						long srsId = geometryData.getSrsId();
						SpatialReferenceSystem srs = srsDao
								.queryForId(srsId);

						long epsg = srs.getOrganizationCoordsysId();
						Projection projection = srs.getProjection();
						long toEpsg = -1;
						if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) {
							toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
						} else {
							toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM;
						}
						ProjectionTransform transformTo = projection
								.getTransformation(toEpsg);
						ProjectionTransform transformFrom = srs
								.getTransformation(transformTo
										.getToProjection());

						byte[] bytes = geometryData.getWkbBytes();

						Geometry projectedGeometry = transformTo
								.transform(geometry);
						GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData(
								-1);
						projectedGeometryData
								.setGeometry(projectedGeometry);
						projectedGeometryData.toBytes();
						byte[] projectedBytes = projectedGeometryData
								.getWkbBytes();

						if (epsg > 0) {
							TestCase.assertFalse(equalByteArrays(bytes,
									projectedBytes));
						}

						Geometry restoredGeometry = transformFrom
								.transform(projectedGeometry);

						compareGeometries(geometry, restoredGeometry, .001);
					}
				}

			}
			cursor.close();
		}
	}
}
 
Example 9
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate feature table with metadata
 *
 * @param geoPackage
 * @throws SQLException
 */
private static void validateFeatureTableWithMetadata(GeoPackage geoPackage,
                                                     GeometryColumns geometryColumns, String idColumn,
                                                     List<FeatureColumn> additionalColumns) throws SQLException {

    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    GeometryColumns queryGeometryColumns = dao.queryForId(geometryColumns
            .getId());
    TestCase.assertNotNull(queryGeometryColumns);

    TestCase.assertEquals(geometryColumns.getTableName(),
            queryGeometryColumns.getTableName());
    TestCase.assertEquals(geometryColumns.getColumnName(),
            queryGeometryColumns.getColumnName());
    TestCase.assertEquals(GeometryType.POINT,
            queryGeometryColumns.getGeometryType());
    TestCase.assertEquals(geometryColumns.getZ(),
            queryGeometryColumns.getZ());
    TestCase.assertEquals(geometryColumns.getM(),
            queryGeometryColumns.getM());

    FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns
            .getTableName());
    FeatureRow featureRow = featureDao.newRow();

    TestCase.assertEquals(
            2 + (additionalColumns != null ? additionalColumns.size() : 0),
            featureRow.columnCount());
    if (idColumn == null) {
        idColumn = "id";
    }
    TestCase.assertEquals(idColumn, featureRow.getColumnName(0));
    TestCase.assertEquals(geometryColumns.getColumnName(),
            featureRow.getColumnName(1));

    if (additionalColumns != null) {
        TestCase.assertEquals("test_text", featureRow.getColumnName(2));
        TestCase.assertEquals("test_real", featureRow.getColumnName(3));
        TestCase.assertEquals("test_boolean", featureRow.getColumnName(4));
        TestCase.assertEquals("test_blob", featureRow.getColumnName(5));
        TestCase.assertEquals("test_integer", featureRow.getColumnName(6));
        TestCase.assertEquals("test_text_limited",
                featureRow.getColumnName(7));
        TestCase.assertEquals("test_blob_limited",
                featureRow.getColumnName(8));
    }
}
 
Example 10
Source File: FeatureUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test update
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testUpdate(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
			testUpdate(dao);

		}
	}

}
 
Example 11
Source File: FeaturePreviewUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * 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 12
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test transforming geometries between projections
 *
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGeometryProjectionTransform(GeoPackage geoPackage)
        throws SQLException, IOException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();

    if (geometryColumnsDao.isTableExists()) {
        List<GeometryColumns> results = geometryColumnsDao.queryForAll();

        for (GeometryColumns geometryColumns : results) {

            FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
            TestCase.assertNotNull(dao);

            FeatureCursor cursor = dao.queryForAll();

            while (cursor.moveToNext()) {

                GeoPackageGeometryData geometryData = cursor.getGeometry();
                if (geometryData != null) {

                    Geometry geometry = geometryData.getGeometry();

                    if (geometry != null) {

                        SpatialReferenceSystemDao srsDao = geoPackage
                                .getSpatialReferenceSystemDao();
                        long srsId = geometryData.getSrsId();
                        SpatialReferenceSystem srs = srsDao
                                .queryForId(srsId);

                        long epsg = srs.getOrganizationCoordsysId();
                        Projection projection = srs.getProjection();
                        long toEpsg = -1;
                        if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) {
                            toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
                        } else {
                            toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM;
                        }
                        ProjectionTransform transformTo = projection
                                .getTransformation(toEpsg);
                        ProjectionTransform transformFrom = srs.getTransformation(transformTo
                                .getToProjection());

                        byte[] bytes = geometryData.getWkbBytes();

                        Geometry projectedGeometry = transformTo
                                .transform(geometry);
                        GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData(
                                -1);
                        projectedGeometryData
                                .setGeometry(projectedGeometry);
                        projectedGeometryData.toBytes();
                        byte[] projectedBytes = projectedGeometryData
                                .getWkbBytes();

                        if (epsg > 0) {
                            TestCase.assertFalse(equalByteArrays(bytes,
                                    projectedBytes));
                        }

                        Geometry restoredGeometry = transformFrom
                                .transform(projectedGeometry);

                        compareGeometries(geometry, restoredGeometry, .001);
                    }
                }

            }
            cursor.close();
        }
    }
}
 
Example 13
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createFeatureStylesGeometry1(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry1");
    FeatureTableStyles geometry1Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry1Styles.setTableStyleDefault(styles.get(0));
    geometry1Styles.setTableStyle(GeometryType.POLYGON, styles.get(1));
    geometry1Styles.setTableStyle(GeometryType.POINT, styles.get(2));

    geometry1Styles.createStyleRelationship();
    geometry1Styles.createIconRelationship();

    int pointCount = 0;
    int lineCount = 0;
    int polygonCount = 0;

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                pointCount++;
                switch (pointCount) {
                    case 1:
                        geometry1Styles.setIcon(featureRow, icons.get(0));
                        break;
                    case 2:
                        geometry1Styles.setIcon(featureRow, icons.get(1));
                        break;
                    case 3:
                        geometry1Styles.setIcon(featureRow, icons.get(2));
                        break;
                }
                break;
            case LINESTRING:
                lineCount++;
                switch (lineCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(1));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            case POLYGON:
                polygonCount++;
                switch (polygonCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(3));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            default:
        }
    }
    features.close();

}
 
Example 14
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createRelatedTablesTilesExtension(
		GeoPackage geoPackage) {

	String featureTable = "point2";
	String tileTable = "nga";

	RelatedTablesExtension relatedTables = new RelatedTablesExtension(
			geoPackage);

	List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
			.createAdditionalUserColumns();

	UserMappingTable userMappingTable = UserMappingTable.create(
			featureTable + "_" + tileTable, additionalMappingColumns);
	ExtendedRelation relation = relatedTables.addTilesRelationship(
			featureTable, tileTable, userMappingTable);

	UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

	FeatureDao featureDao = geoPackage
			.getFeatureDao(relation.getBaseTableName());
	TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName());

	FeatureResultSet featureResultSet = featureDao.queryForAll();
	while (featureResultSet.moveToNext()) {

		FeatureRow featureRow = featureResultSet.getRow();
		String featureName = featureRow.getValue(TEXT_COLUMN).toString();

		TileResultSet tileResultSet = tileDao
				.queryForTile(tileDao.getMinZoom());
		while (tileResultSet.moveToNext()) {

			TileRow tileRow = tileResultSet.getRow();

			UserMappingRow userMappingRow = userMappingDao.newRow();
			userMappingRow.setBaseId(featureRow.getId());
			userMappingRow.setRelatedId(tileRow.getId());
			RelatedTablesUtils.populateUserRow(userMappingDao.getTable(),
					userMappingRow, UserMappingTable.requiredColumns());
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.TITLE, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.DESCRIPTION, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.SOURCE, featureName);
			userMappingDao.create(userMappingRow);
		}
		tileResultSet.close();

	}
	featureResultSet.close();

}
 
Example 15
Source File: FeatureTableIndexUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test table index delete all
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteAll(GeoPackage geoPackage) throws SQLException {

	// Test indexing each feature table
	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTableIndex featureTableIndex = new FeatureTableIndex(
				geoPackage, featureDao);

		if (featureTableIndex.isIndexed()) {
			featureTableIndex.deleteIndex();
		}

		TestCase.assertFalse(featureTableIndex.isIndexed());

		TestUtils.validateGeoPackage(geoPackage);

		// Test indexing
		featureTableIndex.index();
		TestUtils.validateGeoPackage(geoPackage);

		TestCase.assertTrue(featureTableIndex.isIndexed());

	}

	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
	GeometryIndexDao geometryIndexDao = geoPackage.getGeometryIndexDao();
	TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();

	TestCase.assertTrue(geometryIndexDao.isTableExists());
	TestCase.assertTrue(tableIndexDao.isTableExists());
	TestCase.assertTrue(extensionsDao.queryByExtension(
			FeatureTableIndex.EXTENSION_NAME).size() > 0);

	TestCase.assertTrue(geometryIndexDao.countOf() > 0);
	long count = tableIndexDao.countOf();
	TestCase.assertTrue(count > 0);

	int deleteCount = tableIndexDao.deleteAllCascade();
	TestCase.assertEquals(count, deleteCount);

	TestCase.assertTrue(geometryIndexDao.countOf() == 0);
	TestCase.assertTrue(tableIndexDao.countOf() == 0);
}
 
Example 16
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate feature table with metadata
 * 
 * @param geoPackage
 * @throws SQLException
 */
private static void validateFeatureTableWithMetadata(GeoPackage geoPackage,
		GeometryColumns geometryColumns, String idColumn,
		List<FeatureColumn> additionalColumns) throws SQLException {

	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	GeometryColumns queryGeometryColumns = dao
			.queryForId(geometryColumns.getId());
	TestCase.assertNotNull(queryGeometryColumns);

	TestCase.assertEquals(geometryColumns.getTableName(),
			queryGeometryColumns.getTableName());
	TestCase.assertEquals(geometryColumns.getColumnName(),
			queryGeometryColumns.getColumnName());
	TestCase.assertEquals(GeometryType.POINT,
			queryGeometryColumns.getGeometryType());
	TestCase.assertEquals(geometryColumns.getZ(),
			queryGeometryColumns.getZ());
	TestCase.assertEquals(geometryColumns.getM(),
			queryGeometryColumns.getM());

	FeatureDao featureDao = geoPackage
			.getFeatureDao(geometryColumns.getTableName());
	FeatureRow featureRow = featureDao.newRow();

	TestCase.assertEquals(
			2 + (additionalColumns != null ? additionalColumns.size() : 0),
			featureRow.columnCount());
	if (idColumn == null) {
		idColumn = "id";
	}
	TestCase.assertEquals(idColumn, featureRow.getColumnName(0));
	TestCase.assertEquals(geometryColumns.getColumnName(),
			featureRow.getColumnName(1));

	if (additionalColumns != null) {
		TestCase.assertEquals("test_text", featureRow.getColumnName(2));
		TestCase.assertEquals("test_real", featureRow.getColumnName(3));
		TestCase.assertEquals("test_boolean", featureRow.getColumnName(4));
		TestCase.assertEquals("test_blob", featureRow.getColumnName(5));
		TestCase.assertEquals("test_integer", featureRow.getColumnName(6));
		TestCase.assertEquals("test_text_limited",
				featureRow.getColumnName(7));
		TestCase.assertEquals("test_blob_limited",
				featureRow.getColumnName(8));
	}
}
 
Example 17
Source File: FeatureTableIndexUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test table index delete all
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteAll(GeoPackage geoPackage) throws SQLException {

    // Test indexing each feature table
    List<String> featureTables = geoPackage.getFeatureTables();
    for (String featureTable : featureTables) {

        FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
        FeatureTableIndex featureTableIndex = new FeatureTableIndex(
                geoPackage, featureDao);

        if(featureTableIndex.isIndexed()){
            featureTableIndex.deleteIndex();
        }

        TestCase.assertFalse(featureTableIndex.isIndexed());

        TestUtils.validateGeoPackage(geoPackage);

        // Test indexing
        featureTableIndex.index();
        TestUtils.validateGeoPackage(geoPackage);

        TestCase.assertTrue(featureTableIndex.isIndexed());

    }

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
    GeometryIndexDao geometryIndexDao = geoPackage.getGeometryIndexDao();
    TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();

    TestCase.assertTrue(geometryIndexDao.isTableExists());
    TestCase.assertTrue(tableIndexDao.isTableExists());
    TestCase.assertTrue(extensionsDao.queryByExtension(
            FeatureTableIndex.EXTENSION_NAME).size() > 0);

    TestCase.assertTrue(geometryIndexDao.countOf() > 0);
    long count = tableIndexDao.countOf();
    TestCase.assertTrue(count > 0);

    int deleteCount = tableIndexDao.deleteAllCascade();
    TestCase.assertEquals(count, deleteCount);

    TestCase.assertTrue(geometryIndexDao.countOf() == 0);
    TestCase.assertTrue(tableIndexDao.countOf() == 0);
}
 
Example 18
Source File: GeoPackageExample.java    From geopackage-android with MIT License 3 votes vote down vote up
private static void createRTreeSpatialIndexExtension(GeoPackage geoPackage) {

        RTreeIndexExtension extension = new RTreeIndexExtension(geoPackage);

        List<String> featureTables = geoPackage.getFeatureTables();
        for (String tableName : featureTables) {

            FeatureDao featureDao = geoPackage.getFeatureDao(tableName);
            FeatureTable featureTable = featureDao.getTable();

            extension.create(featureTable);
        }

    }
 
Example 19
Source File: GeoPackageExample.java    From geopackage-java with MIT License 3 votes vote down vote up
private static void createRTreeSpatialIndexExtension(
		GeoPackage geoPackage) {

	RTreeIndexExtension extension = new RTreeIndexExtension(geoPackage);

	List<String> featureTables = geoPackage.getFeatureTables();
	for (String tableName : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(tableName);
		FeatureTable featureTable = featureDao.getTable();

		extension.create(featureTable);
	}

}
 
Example 20
Source File: FeaturePreview.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Constructor
 *
 * @param context      context
 * @param geoPackage   GeoPackage
 * @param featureTable feature table
 */
public FeaturePreview(Context context, GeoPackage geoPackage, String featureTable) {
    this(context, geoPackage, geoPackage.getFeatureDao(featureTable));
}