Skip to main content
A TileDao provides access to raster tiles stored in a GeoPackage tile table. Each tile is identified by its column, row, and zoom level. Obtain a TileDao from an open GeoPackage.
const tileDao = geoPackage.getTileDao('imagery');
TileDao extends UserDao, so generic row operations such as queryForAll(), create(), update(), and deleteById() are also available.

Creating a TileDao

getTileDao()

Call this on an open GeoPackage to get a TileDao for the named tile table.
geoPackage.getTileDao(tableName: string): TileDao
const tileDao = geoPackage.getTileDao('world_imagery');

Querying tiles

queryForTile()

Returns the TileRow at the given tile grid coordinates, or null if no tile exists at that location.
queryForTile(column: number, row: number, zoomLevel: number): TileRow
column
number
required
Tile column index (x-axis).
row
number
required
Tile row index (y-axis).
zoomLevel
number
required
Zoom level of the requested tile.
return
TileRow | null
The matching tile row, or null if not found.
const tile = tileDao.queryForTile(3, 2, 5);
if (tile) {
  const bytes = tile.getTileData();
}

queryForTiles()

Returns a TileResultSet of all tiles at the specified zoom level.
queryForTiles(zoomLevel: number): TileResultSet
zoomLevel
number
required
Zoom level to query.
return
TileResultSet
Result set that should be closed after use.
const results = tileDao.queryForTiles(4);
try {
  while (results.moveToNext()) {
    const row = results.getRow();
    console.log(row.getTileColumn(), row.getTileRow(), row.getTileData()?.length);
  }
} finally {
  results.close();
}

queryByTileGrid()

Returns a TileResultSet for all tiles within the given TileGrid at a zoom level. Use this for range queries across columns and rows.
queryByTileGrid(tileGrid: TileGrid, zoomLevel: number, orderBy?: string): TileResultSet
tileGrid
TileGrid
required
A TileGrid specifying min/max column and min/max row bounds.
zoomLevel
number
required
Zoom level to query.
orderBy
string
Optional SQL ORDER BY expression.
return
TileResultSet | null
Result set, or null if the tile grid is null.
import { TileGrid } from '@ngageoint/geopackage';

// Columns 2–4, rows 1–3 at zoom 5
const grid = new TileGrid(2, 1, 4, 3);
const results = tileDao.queryByTileGrid(grid, 5);

queryForTilesInColumn()

Returns a TileResultSet of all tiles in a specific column at a zoom level.
queryForTilesInColumn(column: number, zoomLevel: number): TileResultSet

queryForTilesInRow()

Returns a TileResultSet of all tiles in a specific row at a zoom level.
queryForTilesInRow(row: number, zoomLevel: number): TileResultSet

deleteTile()

Deletes the tile at the specified coordinates. Returns the number of rows deleted.
deleteTile(column: number, row: number, zoomLevel: number): number

Zoom level helpers

getMinZoom()

Returns the minimum zoom level present in this tile table.
getMinZoom(): number

getMaxZoom()

Returns the maximum zoom level present in this tile table.
getMaxZoom(): number

getZoomLevels()

Returns an array of all zoom levels that have a corresponding TileMatrix entry.
getZoomLevels(): number[]
const zooms = tileDao.getZoomLevels(); // [0, 1, 2, 3, 4, 5]

getTileMatrix()

Returns the TileMatrix for a specific zoom level, or null if none exists.
getTileMatrix(zoomLevel: number): TileMatrix
zoomLevel
number
required
Zoom level to look up.
return
TileMatrix | null
The tile matrix describing tile dimensions and pixel sizes at this zoom, or null.

getTileMatrixSet()

Returns the TileMatrixSet that defines the spatial extent and SRS for the entire tile table.
getTileMatrixSet(): TileMatrixSet

getTileGrid()

Returns a TileGrid representing the full column/row range at the given zoom level, or null.
getTileGrid(zoomLevel: number): TileGrid

countAtZoomLevel()

Returns the number of tiles stored at a specific zoom level.
countAtZoomLevel(zoomLevel: number): number

TileRow

A TileRow is a single row returned from a tile table query, containing the encoded image bytes and the tile’s position.

getTileData()

Returns the raw encoded image bytes for this tile.
getTileData(): Buffer | Uint8Array
return
Buffer | Uint8Array
The raw image bytes (typically PNG or JPEG).

getTileDataImage()

Decodes the tile bytes and returns a Promise<GeoPackageImage>.
getTileDataImage(): Promise<GeoPackageImage>

getTileColumn()

Returns the tile column index (x position) for this row.
getTileColumn(): number

getTileRow()

Returns the tile row index (y position) for this row.
getTileRow(): number

getZoomLevel()

Returns the zoom level of this tile.
getZoomLevel(): number

getId()

Returns the primary key value of this row.
getId(): number

Full example

import { GeoPackageManager } from '@ngageoint/geopackage';

const geoPackage = await GeoPackageManager.open('./tiles.gpkg');
const tileDao = geoPackage.getTileDao('world_imagery');

console.log('Zoom levels:', tileDao.getZoomLevels());
console.log('Min zoom:', tileDao.getMinZoom(), 'Max zoom:', tileDao.getMaxZoom());

// Retrieve a specific tile
const tile = tileDao.queryForTile(0, 0, 0);
if (tile) {
  const bytes = tile.getTileData();
  console.log('Tile size (bytes):', bytes?.length);
  console.log('Position:', tile.getTileColumn(), tile.getTileRow(), 'z:', tile.getZoomLevel());
}

geoPackage.close();

Build docs developers (and LLMs) love