Skip to content

Commit 99c51c0

Browse files
committed
Improve GeoPackage support implementation:
- Add support of local tile origin based on tile matrix set extent instead of full sphere origin. - Add surface image name based on content identifier. - Change level set sector initialization based on tile matrix set extent instead of content extent. - Change first level tile delta and number of levels calculation based on tile matrix zoom levels. - Fix row calculation in tile factory.
1 parent 88e6f0e commit 99c51c0

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

worldwind/src/main/java/gov/nasa/worldwind/layer/LayerFactory.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.net.Uri;
99
import android.os.Handler;
1010
import android.os.Looper;
11+
import android.util.SparseArray;
1112

1213
import java.io.BufferedInputStream;
1314
import java.io.InputStream;
@@ -30,6 +31,7 @@
3031
import gov.nasa.worldwind.ogc.gpkg.GpkgContent;
3132
import gov.nasa.worldwind.ogc.gpkg.GpkgSpatialReferenceSystem;
3233
import gov.nasa.worldwind.ogc.gpkg.GpkgTileFactory;
34+
import gov.nasa.worldwind.ogc.gpkg.GpkgTileMatrix;
3335
import gov.nasa.worldwind.ogc.gpkg.GpkgTileMatrixSet;
3436
import gov.nasa.worldwind.ogc.gpkg.GpkgTileUserMetrics;
3537
import gov.nasa.worldwind.ogc.wms.WmsCapabilities;
@@ -259,6 +261,13 @@ protected void createFromGeoPackageAsync(String pathName, Layer layer, Callback
259261
continue;
260262
}
261263

264+
SparseArray<GpkgTileMatrix> tileMatrix = geoPackage.getTileMatrix(content.getTableName());
265+
if (tileMatrix == null || tileMatrix.size() == 0) {
266+
Logger.logMessage(Logger.WARN, "LayerFactory", "createFromGeoPackageAsync",
267+
"Unsupported GeoPackage tile matrix");
268+
continue;
269+
}
270+
262271
GpkgTileUserMetrics tileMetrics = geoPackage.getTileUserMetrics(content.getTableName());
263272
if (tileMetrics == null) {
264273
Logger.logMessage(Logger.WARN, "LayerFactory", "createFromGeoPackageAsync",
@@ -267,14 +276,15 @@ protected void createFromGeoPackageAsync(String pathName, Layer layer, Callback
267276
}
268277

269278
LevelSetConfig config = new LevelSetConfig();
270-
config.sector.set(content.getMinY(), content.getMinX(),
271-
content.getMaxY() - content.getMinY(), content.getMaxX() - content.getMinX());
272-
config.firstLevelDelta = 180;
273-
config.numLevels = tileMetrics.getMaxZoomLevel() + 1; // zero when there are no zoom levels, (0 = -1 + 1)
274-
config.tileWidth = 256;
275-
config.tileHeight = 256;
279+
config.sector.set(tileMatrixSet.getMinY(), tileMatrixSet.getMinX(),
280+
tileMatrixSet.getMaxY() - tileMatrixSet.getMinY(),
281+
tileMatrixSet.getMaxX() - tileMatrixSet.getMinX());
282+
config.tileOrigin.set(tileMatrixSet.getMinY(), tileMatrixSet.getMinX());
283+
config.firstLevelDelta = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / tileMatrix.valueAt(0).getMatrixHeight();
284+
config.numLevels = tileMatrix.size();
276285

277286
TiledSurfaceImage surfaceImage = new TiledSurfaceImage();
287+
surfaceImage.setDisplayName(content.getIdentifier());
278288
surfaceImage.setLevelSet(new LevelSet(config));
279289
surfaceImage.setTileFactory(new GpkgTileFactory(content));
280290
gpkgRenderables.addRenderable(surfaceImage);

worldwind/src/main/java/gov/nasa/worldwind/ogc/gpkg/GpkgTileFactory.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package gov.nasa.worldwind.ogc.gpkg;
77

8+
import android.util.SparseArray;
9+
810
import gov.nasa.worldwind.geom.Sector;
911
import gov.nasa.worldwind.render.ImageSource;
1012
import gov.nasa.worldwind.render.ImageTile;
@@ -40,23 +42,24 @@ public Tile createTile(Sector sector, Level level, int row, int column) {
4042

4143
ImageTile tile = new ImageTile(sector, level, row, column);
4244

43-
String tableName = this.tiles.getTableName();
44-
int zoomLevel = level.levelNumber;
45-
46-
// Attempt to find the GeoPackage tile matrix associated with the WorldWind level. Assumes that the WorldWind
47-
// levels match the GeoPackage tile matrix zoom levels. If there's no match then the GeoPackage contains no
48-
// tiles for this level and this tile has no image source.
4945
GeoPackage geoPackage = this.tiles.getContainer();
50-
GpkgTileMatrix tileMatrix = geoPackage.getTileMatrix(tableName).get(zoomLevel);
46+
String tableName = this.tiles.getTableName();
47+
SparseArray<GpkgTileMatrix> tileMatrixByZoomLevel = geoPackage.getTileMatrix(tableName);
5148
GpkgTileUserMetrics tileUserMetrics = geoPackage.getTileUserMetrics(tableName);
5249

50+
// Attempt to find the GeoPackage tile matrix associated with the WorldWind level.
51+
int zoomLevel = level.levelNumber + tileMatrixByZoomLevel.keyAt(0);
52+
GpkgTileMatrix tileMatrix = tileMatrixByZoomLevel.get(zoomLevel);
53+
54+
// Check if content table has any tiles on this zoom level.
5355
if (tileMatrix != null && tileUserMetrics.hasZoomLevel(zoomLevel)) {
54-
// Convert the WorldWind tile address to the equivalent GeoPackage tile address. Assumes that the World
55-
// Wind level set matchs the GeoPackage tile matrix set, with the exception of tile rows which are inverted.
56-
int gpkgRow = tileMatrix.getMatrixHeight() - row - 1;
57-
// Configure the tile with a bitmap factory that reads directly from the GeoPackage.
58-
ImageSource.BitmapFactory bitmapFactory = new GpkgBitmapFactory(this.tiles, zoomLevel, column, gpkgRow);
59-
tile.setImageSource(ImageSource.fromBitmapFactory(bitmapFactory));
56+
// Convert the WorldWind tile row to the equivalent GeoPackage tile row.
57+
int gpkgRow = level.levelHeight / level.tileHeight - row - 1;
58+
if (column < tileMatrix.getMatrixWidth() && gpkgRow < tileMatrix.getMatrixHeight()) {
59+
// Configure the tile with a bitmap factory that reads directly from the GeoPackage.
60+
ImageSource.BitmapFactory bitmapFactory = new GpkgBitmapFactory(this.tiles, zoomLevel, column, gpkgRow);
61+
tile.setImageSource(ImageSource.fromBitmapFactory(bitmapFactory));
62+
}
6063
}
6164

6265
return tile;

0 commit comments

Comments
 (0)