use of mil.nga.geopackage.tiles.user.TileDao in project geopackage-android-map by ngageoint.
the class GeoPackageOverlayUtils method testOverlay.
/**
* Test overlay
*
* @param geoPackage
* @throws SQLException
*/
public static void testOverlay(GeoPackage geoPackage) throws SQLException {
TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
if (tileMatrixSetDao.isTableExists()) {
List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();
for (TileMatrixSet tileMatrixSet : results) {
TileDao dao = geoPackage.getTileDao(tileMatrixSet);
GeoPackageOverlay overlay = new GeoPackageOverlay(dao);
for (int zoom = 0; zoom <= 21; zoom++) {
int tileLength = (int) Math.pow(2, zoom);
int column = (int) (Math.random() * tileLength);
int row = (int) (Math.random() * tileLength);
for (int maxColumns = Math.min(tileLength, column + 2); column < maxColumns; column++) {
for (int maxRows = Math.min(tileLength, row + 2); row < maxRows; row++) {
Tile tile = overlay.getTile(column, row, zoom);
if (tile != null) {
TestCase.assertTrue(tile.height > 0);
TestCase.assertTrue(tile.width > 0);
}
}
}
}
}
}
}
use of mil.nga.geopackage.tiles.user.TileDao 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();
}
use of mil.nga.geopackage.tiles.user.TileDao in project geopackage-android-map by ngageoint.
the class TestUtils method addRowsToTileTable.
/**
* Add rows to the tile table
*
* @param geoPackage
* @param tileMatrix
* @param tileData
*/
public static void addRowsToTileTable(GeoPackage geoPackage, TileMatrix tileMatrix, byte[] tileData) {
TileDao dao = geoPackage.getTileDao(tileMatrix.getTableName());
for (int column = 0; column < tileMatrix.getMatrixWidth(); column++) {
for (int row = 0; row < tileMatrix.getMatrixHeight(); row++) {
TileRow newRow = dao.newRow();
newRow.setZoomLevel(tileMatrix.getZoomLevel());
newRow.setTileColumn(column);
newRow.setTileRow(row);
newRow.setTileData(tileData);
dao.create(newRow);
}
}
}
use of mil.nga.geopackage.tiles.user.TileDao in project geopackage-android-map by ngageoint.
the class GeoPackageOverlayFactory method getCompositeOverlay.
/**
* Create a composite overlay by adding tile overlays for the tile DAOs
*
* @param tileDaos collection of tile daos
* @return composite overlay
*/
public static CompositeOverlay getCompositeOverlay(Collection<TileDao> tileDaos) {
CompositeOverlay compositeOverlay = new CompositeOverlay();
for (TileDao tileDao : tileDaos) {
BoundedOverlay boundedOverlay = GeoPackageOverlayFactory.getBoundedOverlay(tileDao);
compositeOverlay.addOverlay(boundedOverlay);
}
return compositeOverlay;
}
use of mil.nga.geopackage.tiles.user.TileDao in project geopackage-android-map by ngageoint.
the class GeoPackageOverlayFactory method getLinkedFeatureOverlay.
/**
* Create a composite overlay linking the feature overly with
*
* @param featureOverlay feature overlay
* @param geoPackage GeoPackage
* @return linked bounded overlay
*/
public static BoundedOverlay getLinkedFeatureOverlay(FeatureOverlay featureOverlay, GeoPackage geoPackage) {
BoundedOverlay overlay;
// Get the linked tile daos
FeatureTileTableLinker linker = new FeatureTileTableLinker(geoPackage);
List<TileDao> tileDaos = linker.getTileDaosForFeatureTable(featureOverlay.getFeatureTiles().getFeatureDao().getTableName());
if (!tileDaos.isEmpty()) {
// Create a composite overlay to search for existing tiles before drawing from features
overlay = getCompositeOverlay(tileDaos, featureOverlay);
} else {
overlay = featureOverlay;
}
return overlay;
}
Aggregations