Search in sources :

Example 1 with GeoPackageManager

use of mil.nga.geopackage.GeoPackageManager in project geopackage-android-map by ngageoint.

the class ReadmeTest method testGeoPackage.

/**
 * Test transform
 *
 * @throws IOException  upon error
 * @throws SQLException upon error
 */
// @Test
public void testGeoPackage() throws IOException, SQLException {
    geoPackage.close();
    geoPackage = null;
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    manager.delete(TestConstants.IMPORT_DB_NAME);
    String importLocation = TestUtils.getAssetFileInternalStorageLocation(activity, TestConstants.IMPORT_DB_FILE_NAME);
    File geoPackageFile = new File(importLocation);
    // test map?
    GoogleMap map = null;
    try {
        testGeoPackage(activity, geoPackageFile, map);
    } finally {
        manager.delete(TestConstants.IMPORT_DB_NAME);
    }
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) GeoPackageManager(mil.nga.geopackage.GeoPackageManager) File(java.io.File)

Example 2 with GeoPackageManager

use of mil.nga.geopackage.GeoPackageManager in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method tearDownCreate.

/**
 * 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);
}
Also used : GeoPackageManager(mil.nga.geopackage.GeoPackageManager)

Example 3 with GeoPackageManager

use of mil.nga.geopackage.GeoPackageManager in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpCreate.

/**
 * 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().intValue(), 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().intValue(), Integer.valueOf(majorVersion).intValue());
    TestCase.assertEquals("Minor User Version", geoPackage.getUserVersionMinor().intValue(), Integer.valueOf(minorVersion).intValue());
    TestCase.assertEquals("Patch User Version", geoPackage.getUserVersionPatch().intValue(), Integer.valueOf(patchVersion).intValue());
    if (features) {
        setUpCreateFeatures(geoPackage, allowEmptyFeatures);
    }
    if (tiles) {
        setUpCreateTiles(testContext, geoPackage);
    }
    setUpCreateCommon(geoPackage);
    return geoPackage;
}
Also used : GeoPackageManager(mil.nga.geopackage.GeoPackageManager) GeoPackage(mil.nga.geopackage.GeoPackage) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 4 with GeoPackageManager

use of mil.nga.geopackage.GeoPackageManager in project geopackage-android-map by ngageoint.

the class ReadmeTest method testGeoPackage.

/**
 * Test GeoPackage
 *
 * @param context        context
 * @param geoPackageFile GeoPackage file
 * @param map            Google map
 * @throws IOException  upon error
 * @throws SQLException upon error
 */
private void testGeoPackage(Context context, File geoPackageFile, GoogleMap map) throws IOException, SQLException {
    // Context context = ...;
    // File geoPackageFile = ...;
    // GoogleMap map = ...;
    // Get a manager
    GeoPackageManager manager = GeoPackageFactory.getManager(context);
    // Import database
    boolean imported = manager.importGeoPackage(geoPackageFile);
    // Available databases
    List<String> databases = manager.databases();
    // Open database
    GeoPackage geoPackage = manager.open(databases.get(0));
    // GeoPackage Table DAOs
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();
    GeometryColumnsDao geomColumnsDao = geoPackage.getGeometryColumnsDao();
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    SchemaExtension schemaExtension = new SchemaExtension(geoPackage);
    DataColumnsDao dao = schemaExtension.getDataColumnsDao();
    DataColumnConstraintsDao dataColumnConstraintsDao = schemaExtension.getDataColumnConstraintsDao();
    MetadataExtension metadataExtension = new MetadataExtension(geoPackage);
    MetadataDao metadataDao = metadataExtension.getMetadataDao();
    MetadataReferenceDao metadataReferenceDao = metadataExtension.getMetadataReferenceDao();
    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
    // Feature and tile tables
    List<String> features = geoPackage.getFeatureTables();
    List<String> tiles = geoPackage.getTileTables();
    // Query Features
    String featureTable = features.get(0);
    FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
    GoogleMapShapeConverter converter = new GoogleMapShapeConverter(featureDao.getProjection());
    FeatureCursor featureCursor = featureDao.queryForAll();
    try {
        for (FeatureRow featureRow : featureCursor) {
            GeoPackageGeometryData geometryData = featureRow.getGeometry();
            if (geometryData != null && !geometryData.isEmpty()) {
                Geometry geometry = geometryData.getGeometry();
                GoogleMapShape shape = converter.toShape(geometry);
                GoogleMapShape mapShape = GoogleMapShapeConverter.addShapeToMap(map, shape);
            // ...
            }
        }
    } finally {
        featureCursor.close();
    }
    // Query Tiles
    String tileTable = tiles.get(0);
    TileDao tileDao = geoPackage.getTileDao(tileTable);
    TileCursor tileCursor = tileDao.queryForAll();
    try {
        for (TileRow tileRow : tileCursor) {
            byte[] tileBytes = tileRow.getTileData();
            Bitmap tileBitmap = tileRow.getTileDataBitmap();
        // ...
        }
    } finally {
        tileCursor.close();
    }
    // Retrieve Tiles by XYZ
    GeoPackageTileRetriever retriever = new GeoPackageTileRetriever(tileDao);
    GeoPackageTile geoPackageTile = retriever.getTile(2, 2, 2);
    if (geoPackageTile != null) {
        byte[] tileBytes = geoPackageTile.getData();
        Bitmap tileBitmap = geoPackageTile.getBitmap();
    // ...
    }
    // Retrieve Tiles by Bounding Box
    TileCreator tileCreator = new TileCreator(tileDao, ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM));
    GeoPackageTile geoPackageTile2 = tileCreator.getTile(new BoundingBox(-90.0, 0.0, 0.0, 66.513260));
    if (geoPackageTile2 != null) {
        byte[] tileBytes = geoPackageTile2.getData();
        Bitmap tileBitmap = geoPackageTile2.getBitmap();
    // ...
    }
    // Tile Provider (GeoPackage or Google API)
    TileProvider overlay = GeoPackageOverlayFactory.getTileProvider(tileDao);
    TileOverlayOptions overlayOptions = new TileOverlayOptions();
    overlayOptions.tileProvider(overlay);
    overlayOptions.zIndex(-1);
    map.addTileOverlay(overlayOptions);
    BoundingBox boundingBox = BoundingBox.worldWebMercator();
    Projection projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
    // Index Features
    FeatureIndexManager indexer = new FeatureIndexManager(context, geoPackage, featureDao);
    indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
    int indexedCount = indexer.index();
    // Query Indexed Features in paginated chunks
    FeatureIndexResults indexResults = indexer.queryForChunk(boundingBox, projection, 50);
    FeaturePaginatedCursor paginatedCursor = indexer.paginate(indexResults);
    for (FeatureRow featureRow : paginatedCursor) {
        GeoPackageGeometryData geometryData = featureRow.getGeometry();
        if (geometryData != null && !geometryData.isEmpty()) {
            Geometry geometry = geometryData.getGeometry();
        // ...
        }
    }
    // Feature Tile Provider (dynamically draw tiles from features)
    FeatureTiles featureTiles = new DefaultFeatureTiles(context, featureDao, context.getResources().getDisplayMetrics().density);
    // Set max features to draw per tile
    featureTiles.setMaxFeaturesPerTile(1000);
    // Custom feature tile implementation
    NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(context);
    // Draw feature count tiles when max features passed
    featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
    // Set index manager to query feature indices
    featureTiles.setIndexManager(indexer);
    FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
    // Set zoom level to start showing tiles
    featureOverlay.setMinZoom(featureDao.getZoomLevel());
    TileOverlayOptions featureOverlayOptions = new TileOverlayOptions();
    featureOverlayOptions.tileProvider(featureOverlay);
    // Draw the feature tiles behind map markers
    featureOverlayOptions.zIndex(-1);
    map.addTileOverlay(featureOverlayOptions);
    // URL Tile Generator (generate tiles from a URL)
    TileGenerator urlTileGenerator = new UrlTileGenerator(context, geoPackage, "url_tile_table", "http://url/{z}/{x}/{y}.png", 0, 0, boundingBox, projection);
    int urlTileCount = urlTileGenerator.generateTiles();
    // Feature Tile Generator (generate tiles from features)
    TileGenerator featureTileGenerator = new FeatureTileGenerator(context, geoPackage, "tiles_" + featureTable, featureTiles, 1, 2, boundingBox, projection);
    int featureTileCount = featureTileGenerator.generateTiles();
    // Close feature tiles (and indexer)
    featureTiles.close();
    // Close database when done
    geoPackage.close();
}
Also used : MetadataReferenceDao(mil.nga.geopackage.extension.metadata.reference.MetadataReferenceDao) GeoPackageTileRetriever(mil.nga.geopackage.tiles.retriever.GeoPackageTileRetriever) DataColumnsDao(mil.nga.geopackage.extension.schema.columns.DataColumnsDao) Projection(mil.nga.proj.Projection) DefaultFeatureTiles(mil.nga.geopackage.tiles.features.DefaultFeatureTiles) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) GeoPackage(mil.nga.geopackage.GeoPackage) MetadataExtension(mil.nga.geopackage.extension.metadata.MetadataExtension) TileProvider(com.google.android.gms.maps.model.TileProvider) FeatureOverlay(mil.nga.geopackage.map.tiles.overlay.FeatureOverlay) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) Bitmap(android.graphics.Bitmap) FeaturePaginatedCursor(mil.nga.geopackage.features.user.FeaturePaginatedCursor) DataColumnConstraintsDao(mil.nga.geopackage.extension.schema.constraints.DataColumnConstraintsDao) BoundingBox(mil.nga.geopackage.BoundingBox) TileCreator(mil.nga.geopackage.tiles.retriever.TileCreator) MetadataDao(mil.nga.geopackage.extension.metadata.MetadataDao) FeatureIndexResults(mil.nga.geopackage.features.index.FeatureIndexResults) GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) SchemaExtension(mil.nga.geopackage.extension.schema.SchemaExtension) TileOverlayOptions(com.google.android.gms.maps.model.TileOverlayOptions) ExtensionsDao(mil.nga.geopackage.extension.ExtensionsDao) NumberFeaturesTile(mil.nga.geopackage.tiles.features.custom.NumberFeaturesTile) GeoPackageManager(mil.nga.geopackage.GeoPackageManager) UrlTileGenerator(mil.nga.geopackage.tiles.UrlTileGenerator) GoogleMapShapeConverter(mil.nga.geopackage.map.geom.GoogleMapShapeConverter) GoogleMapShape(mil.nga.geopackage.map.geom.GoogleMapShape) Geometry(mil.nga.sf.Geometry) GeoPackageTile(mil.nga.geopackage.tiles.retriever.GeoPackageTile) DefaultFeatureTiles(mil.nga.geopackage.tiles.features.DefaultFeatureTiles) FeatureTiles(mil.nga.geopackage.tiles.features.FeatureTiles) TileMatrixDao(mil.nga.geopackage.tiles.matrix.TileMatrixDao) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureIndexManager(mil.nga.geopackage.features.index.FeatureIndexManager) TileRow(mil.nga.geopackage.tiles.user.TileRow) TileGenerator(mil.nga.geopackage.tiles.TileGenerator) FeatureTileGenerator(mil.nga.geopackage.tiles.features.FeatureTileGenerator) UrlTileGenerator(mil.nga.geopackage.tiles.UrlTileGenerator) FeatureCursor(mil.nga.geopackage.features.user.FeatureCursor) FeatureTileGenerator(mil.nga.geopackage.tiles.features.FeatureTileGenerator) TileMatrixSetDao(mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao) ContentsDao(mil.nga.geopackage.contents.ContentsDao) TileDao(mil.nga.geopackage.tiles.user.TileDao) TileCursor(mil.nga.geopackage.tiles.user.TileCursor) GeometryColumnsDao(mil.nga.geopackage.features.columns.GeometryColumnsDao)

Example 5 with GeoPackageManager

use of mil.nga.geopackage.GeoPackageManager in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpImport.

/**
 * 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;
}
Also used : GeoPackageManager(mil.nga.geopackage.GeoPackageManager) GeoPackage(mil.nga.geopackage.GeoPackage) File(java.io.File) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Aggregations

GeoPackageManager (mil.nga.geopackage.GeoPackageManager)6 GeoPackage (mil.nga.geopackage.GeoPackage)3 File (java.io.File)2 GeoPackageException (mil.nga.geopackage.GeoPackageException)2 Bitmap (android.graphics.Bitmap)1 GoogleMap (com.google.android.gms.maps.GoogleMap)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 TileProvider (com.google.android.gms.maps.model.TileProvider)1 BoundingBox (mil.nga.geopackage.BoundingBox)1 ContentsDao (mil.nga.geopackage.contents.ContentsDao)1 ExtensionsDao (mil.nga.geopackage.extension.ExtensionsDao)1 MetadataDao (mil.nga.geopackage.extension.metadata.MetadataDao)1 MetadataExtension (mil.nga.geopackage.extension.metadata.MetadataExtension)1 MetadataReferenceDao (mil.nga.geopackage.extension.metadata.reference.MetadataReferenceDao)1 SchemaExtension (mil.nga.geopackage.extension.schema.SchemaExtension)1 DataColumnsDao (mil.nga.geopackage.extension.schema.columns.DataColumnsDao)1 DataColumnConstraintsDao (mil.nga.geopackage.extension.schema.constraints.DataColumnConstraintsDao)1 GeometryColumnsDao (mil.nga.geopackage.features.columns.GeometryColumnsDao)1 FeatureIndexManager (mil.nga.geopackage.features.index.FeatureIndexManager)1 FeatureIndexResults (mil.nga.geopackage.features.index.FeatureIndexResults)1