GeoPackage

open class GeoPackage(val pathName: String, val isReadOnly: Boolean = true)

Constructors

Link copied to clipboard
constructor(pathName: String, isReadOnly: Boolean = true)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val core: GeoPackageCore

Underlying NGA GeoPackageCore instance. Exposed for extension plumbing (e.g. constructing a VectorTilesMapboxExtension against this database) — prefer the higher-level helpers on this class for everyday CRUD.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun buildLevelSetConfig(content: GpkgContent): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun buildTileMatrixSet(content: GpkgContent): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun bumpTileValidatedAt(content: GpkgContent, tpudtId: Long, validatedAt: Long): ERROR CLASS: Unresolved name: withContext

Refresh only GpkgTileRevalidation.validatedAt for tile row tpudtId — the 304-Not-Modified path, where the bytes and validators are unchanged but we want the freshness window to restart so the tile isn't re-requested every frame. Read-modify-write preserves the stored ETag / Last-Modified. No-op when the tile has no revalidation row yet.

Link copied to clipboard
suspend fun bumpTileValidatedAtBatch(content: GpkgContent, tiles: Collection<ERROR CLASS: Symbol not found for Triple<kotlin/Int, kotlin/Int, kotlin/Int>>, validatedAt: Long)

Refresh GpkgTileRevalidation.validatedAt for many (z, x, y) tiles of content in ONE write-dispatcher hop and ONE transaction — the coalesced restamp path for validator-less stale tiles, where per-tile commits flooded the write lane during panning. Unlike bumpTileValidatedAt, a tile with no revalidation row yet gets one created (null validators): tiles cached before the side table existed could otherwise never be stamped fresh and re-entered the stale path on every read. Uncached (z, x, y) are skipped.

Link copied to clipboard
suspend fun clearEntry(tableName: String)
Link copied to clipboard
suspend fun clearFeatureCoverage(content: GpkgContent)

Drop every coverage row tied to content. Called when the content table is cleared.

Link copied to clipboard
suspend fun clearTileRevalidation(content: GpkgContent)

Drop every revalidation row tied to content. Called when the content table is cleared.

Link copied to clipboard
suspend fun deleteEntry(tableName: String)

Delete specified content table and its related metadata

Link copied to clipboard
suspend fun evictFeatures(content: GpkgContent, policy: CachePolicy): ERROR CLASS: Unresolved name: withContext

Evict from a features cache per policy, driven by ww_feature_coverage:

Link copied to clipboard
suspend fun evictTiles(content: GpkgContent, policy: CachePolicy): ERROR CLASS: Unresolved name: withContext

Evict image/elevation/vector tiles per policy. Capacity-only: CachePolicy.staleAfter never deletes (stale tiles refresh in place via SWR). CachePolicy.maxEntries (row count) drops oldest-inserted rows first (by id, the autoincrement PK), one row per tile so a tile is never split. No-op when read-only or unbounded.

Link copied to clipboard
open fun geometryToRenderables(geometry: Geometry, style: FeatureStyle?, srsId: Long): List<Renderable>

Convert a Geometry into Renderables using the given (optional) feature style. Public so the WFS cache replay path can call it directly; subclasses can still override to specialise rendering.

Link copied to clipboard
fun getBoundingSector(content: GpkgContent): Sector?
Link copied to clipboard
suspend fun getContent(tableName: String): GpkgContent?
suspend fun getContent(dataType: String, tableNames: List<String>?): List<GpkgContent>
Link copied to clipboard
suspend fun getExtension(tableName: String, columnName: String, extensionName: String): Extensions?
Link copied to clipboard
suspend fun getGriddedCoverage(content: GpkgContent): GriddedCoverage?
Link copied to clipboard
suspend fun getWebService(tableName: String): GpkgWebService?

Direct web-service lookup by table name. Does NOT require a GpkgContent row to exist — capabilities metadata is independent of any tile/feature pyramid being provisioned for the same key, so this query stays cheap and unconditional.

suspend fun getWebService(content: GpkgContent): GpkgWebService?
Link copied to clipboard
fun notifyBlobInsert(tableName: String, policy: CachePolicy, countRows: suspend () -> Long, evict: suspend () -> Unit)

Per-put eviction trigger called after a successful blob upsert in GpkgBlobStore.

Link copied to clipboard
fun notifyFeatureInsert(content: GpkgContent, policy: CachePolicy, insertedRows: Int)

Per-put eviction trigger called after writeFeatureTile; insertedRows accounts for multi-row writes. Note: uid-upserts and bbox-replace can net zero new rows, so the in-memory counter may overcount — eviction reads SQLite ground truth and no-ops harmlessly.

Link copied to clipboard
fun notifyTileInsert(content: GpkgContent, policy: CachePolicy)

Per-put eviction trigger called after writeTileUserData.

Link copied to clipboard
suspend fun read3DTilesDataSize(tableName: String): Long

Total cached bytes in a 3D Tiles blob-store table. Reads the precomputed size_bytes column instead of LENGTH(tile_data) so the scan stays in the row header and doesn't touch every BLOB page.

Link copied to clipboard
suspend fun readCachedFeatures(content: GpkgContent): List<ERROR CLASS: Symbol not found for Pair<mil/nga/sf/Geometry, kotlin/String?>>

Read back features previously cached via replaceCachedFeatures.

Link copied to clipboard
suspend fun readFeatureCoverage(content: GpkgContent, z: Int, x: Int, y: Int): GpkgFeatureCoverage?

Feature coverage row for the tile region (z, x, y) of content's features table, or null when that region has never been fetched.

Link copied to clipboard
suspend fun readFeaturesDataSize(tableName: String): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun readFeaturesInBbox(content: GpkgContent, minX: Double, minY: Double, maxX: Double, maxY: Double): List<ERROR CLASS: Symbol not found for Pair<mil/nga/sf/Geometry, kotlin/String?>>

Read every flat-store feature intersecting the geographic bbox (degrees, EPSG:4326) via the RTree spatial index — the arbitrary-viewport counterpart to readFeatureTile.

Link copied to clipboard
suspend fun readFeatureTile(content: GpkgContent, z: Int, x: Int, y: Int, sector: Sector? = null): List<ERROR CLASS: Symbol not found for Pair<mil/nga/sf/Geometry, kotlin/String?>>

Read the cached features in tile (z, x, y)'s region via the RTree bbox query. The flat store has no per-tile rows, so this returns every feature intersecting the tile bounds; ww_feature_coverage is what records whether the tile was actually fetched.

Link copied to clipboard
suspend fun readGriddedTile(content: GpkgContent, tileUserData: GpkgTileUserData): GriddedTile?
Link copied to clipboard
suspend fun readTileRevalidation(content: GpkgContent, tpudtId: Long): GpkgTileRevalidation?

Cache freshness row (ETag, Last-Modified, GpkgTileRevalidation.validatedAt) for the tile at (z, x, y) in content. Returns null when nothing has been stored for this tile.

Link copied to clipboard
suspend fun readTilesDataSize(tableName: String): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun readTileUserData(content: GpkgContent, zoomLevel: Int, tileColumn: Int, tileRow: Int): GpkgTileUserData?
Link copied to clipboard
suspend fun readTileUserDataId(content: GpkgContent, zoomLevel: Int, tileColumn: Int, tileRow: Int): Long?

The tile-user-data row id (tpudt_id) for (z, x, y), or null if not cached. Selects only the id — never loads the tile blob — so the SWR freshness check stays cheap.

Link copied to clipboard
suspend fun replaceCachedFeatures(content: GpkgContent, rows: List<ERROR CLASS: Symbol not found for Pair<mil/nga/sf/Geometry, kotlin/String?>>): ERROR CLASS: Unresolved name: withContext

Replace every row in one transaction. Used by full-refresh sources (WFS, Shapefile); tile-pyramid sources use writeFeatureTile instead.

Link copied to clipboard
suspend fun setBoundingSector(content: GpkgContent, sector: Sector)

Persist sector as the gpkg_contents bounding box of content — the SRS-aware inverse of getBoundingSector. For EPSG:3857 the latitude range is clamped to the Web-Mercator limits before conversion to meters.

Link copied to clipboard
suspend fun setDisplayName(tableName: String, displayName: String)

Update the user-visible identifier on tableName's registration row.

Link copied to clipboard
suspend fun setup3DTilesContent(tableName: String, displayName: String? = null): GpkgContent

Set up a 3D Tiles GeoPackage extension blob table for tableName. Idempotent: re-opening an existing 3D Tiles content registers the same row + extension entry.

Link copied to clipboard
suspend fun setupFeaturesContent(tableName: String, displayName: String? = null): GpkgContent

Create a features cache table with universal schema (id, geom, tile_*, properties). Tile columns are NULL for bulk-refresh sources, populated for tile-pyramid sources; the composite index keeps per-tile reads O(log n). Idempotent.

Link copied to clipboard
suspend fun setupGriddedCoverageContent(tableName: String, tileMatrixSet: TileMatrixSet, sector: Sector = tileMatrixSet.sector, displayName: String? = null, isFloat: Boolean = false): GpkgContent

Create (or open) a gridded-coverage tile pyramid. Idempotent — re-running after a partial setup or a previous successful run is a no-op.

Link copied to clipboard
suspend fun setupTileMatrices(content: GpkgContent, tileMatrixSet: TileMatrixSet)
suspend fun setupTileMatrices(content: GpkgContent, levelSet: LevelSet)
Link copied to clipboard
suspend fun setupTilesContent(tableName: String, levelSet: LevelSet, displayName: String? = null, imageFormat: String = "image/png"): GpkgContent

Create (or open) an image-tile pyramid table. Idempotent — a prior partial setup or a previous successful run is detected and the existing content row is returned.

Link copied to clipboard
suspend fun setupVectorTilesContent(tableName: String, levelSet: LevelSet, displayName: String? = null, dataType: String = VECTOR_TILES, encoding: VectorTilesEncodingExtension? = null): GpkgContent

Create a tile pyramid for vector tiles. Mirrors setupTilesContent but for a non-raster data_type (typically "vector-tiles") and an arbitrary encoding extension — the user table schema is identical to raster tiles, only the BLOB payload format differs.

Link copied to clipboard
suspend fun setupWebService(tableName: String, type: String, address: String, layerName: String? = null, outputFormat: String? = null, metadata: String? = null, isTransparent: Boolean = false)

Upsert a GpkgWebService row for tableName with the supplied fields. Single entry point for every web-backed cache content (image / elevation / vector-tile / feature) — the previous per-layer-type setup variants have been collapsed here.

Link copied to clipboard
fun shutdown(): ERROR CLASS: Unresolved name: also
Link copied to clipboard
suspend fun updateTilesContent(tableName: String, levelSet: LevelSet, displayName: String?, content: GpkgContent)

Refresh the GpkgContent identifier + bbox to match the layer's current LevelSet.sector and displayName. The level-set sector is the in-memory source of truth for the layer's data extent; this call persists it back to gpkg so the round-trip is safe — open via tryRecoverLevelSet copies the persisted bbox into the level-set sector; the next reopen writes the same value back. Bulk-download mutates the level-set sector before re-binding the cache, so the new extent lands on disk through the same write.

Link copied to clipboard
suspend fun writeFeatureCoverage(content: GpkgContent, z: Int, x: Int, y: Int, etag: String?, httpLastModified: String?, validatedAt: Long, isEmpty: Boolean): ERROR CLASS: Unresolved name: withContext

Upsert the coverage row for the tile region (z, x, y) — validators, validatedAt (epoch- millis just confirmed fresh) and the isEmpty negative-cache flag. Creates / declares the side table on first use.

Link copied to clipboard
suspend fun writeFeatureTile(content: GpkgContent, z: Int, x: Int, y: Int, rows: List<GpkgFeatureRow>, sector: Sector? = null): ERROR CLASS: Unresolved name: withContext

Replace tile (z, x, y)'s features in the flat store and stamp coverage. Rows that carry a stable GpkgFeatureRow.uid upsert by it (so a feature straddling tile borders dedupes to one row); id-less rows replace everything in the tile's bbox. An empty list clears the region and records the negative cache (is_empty) in ww_feature_coverage — no null-geometry sentinel.

Link copied to clipboard
suspend fun writeGriddedTile(content: GpkgContent, zoomLevel: Int, tileColumn: Int, tileRow: Int, scale: Float = 1.0f, offset: Float = 0.0f, min: Float? = null, max: Float? = null, mean: Float? = null, stdDev: Float? = null): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun writeTileCacheEntry(content: GpkgContent, zoomLevel: Int, tileColumn: Int, tileRow: Int, tileData: ByteArray, etag: String? = null, httpLastModified: String? = null, validatedAt: Long? = null, griddedScale: Float? = null, griddedOffset: Float? = null): Long

Single-transaction upsert of one cached tile: blob, optional gridded ancillary row (elevation) and optional freshness row, plus the content last-change stamp. One writeDispatcher hop and one SQLite commit instead of one per statement — the per-tile cache write path is commit-bound. Returns the tile-user-data row id.

Link copied to clipboard
suspend fun writeTileRevalidation(content: GpkgContent, tpudtId: Long, etag: String?, httpLastModified: String?, validatedAt: Long): ERROR CLASS: Unresolved name: withContext
Link copied to clipboard
suspend fun writeTileUserData(content: GpkgContent, zoomLevel: Int, tileColumn: Int, tileRow: Int, tileData: ByteArray): Long

Upsert the tile blob for (z, x, y) and return its tile-user-data row id (the tpudt_id that writeTileRevalidation keys freshness by). The id is stable across rewrites — the row is reused, not re-inserted.