Skip to main content
GeoPackageManager is the entry point for all GeoPackage operations. It is a static class — do not instantiate it. Use it to open an existing GeoPackage file or create a new one, both of which return a GeoPackage instance.

Static properties

version

static readonly version: string
The version of the @ngageoint/geopackage library. Currently "5.0.0".
import { GeoPackageManager } from '@ngageoint/geopackage';

console.log(GeoPackageManager.version); // '5.0.0'

Static methods

open()

Opens an existing GeoPackage. In Node.js, pass a file path. In the browser, pass a Uint8Array of the file’s raw bytes.
static async open(
  gppathOrByteArray: string | Uint8Array | Buffer,
  name?: string
): Promise<GeoPackage>
gppathOrByteArray
string | Uint8Array | Buffer
required
Path to the .gpkg file on disk (Node.js), or a Uint8Array / Buffer containing the raw GeoPackage bytes (browser or in-memory use).
name
string
Optional name for the GeoPackage instance. Defaults to the basename of the file path in Node.js, or 'geopackage' when loading from bytes.
Promise<GeoPackage>
Promise<GeoPackage>
Resolves with an open GeoPackage connection ready for reading and writing.
Errors thrown
  • GeoPackageException: 'Invalid GeoPackage - Invalid GeoPackage Extension' — the file path does not end with .gpkg or a recognised extension.
  • GeoPackageException: 'Unable to initialize canvas.' — the canvas adapter could not be initialised (environment-specific).
  • GeoPackageException: 'Unable to open GeoPackage.' — the file could not be read or the underlying SQLite connection failed.
Node.js — open from file path
import { GeoPackageManager } from '@ngageoint/geopackage';

const geoPackage = await GeoPackageManager.open('/data/countries.gpkg');
try {
  const tables = geoPackage.getFeatureTables();
  console.log('Feature tables:', tables);
} finally {
  geoPackage.close();
}
Browser — open from byte array
import { GeoPackageManager } from '@ngageoint/geopackage';

// Fetch the file and get raw bytes
const response = await fetch('/assets/countries.gpkg');
const buffer = await response.arrayBuffer();
const bytes = new Uint8Array(buffer);

const geoPackage = await GeoPackageManager.open(bytes, 'countries');
try {
  const tables = geoPackage.getFeatureTables();
  console.log('Feature tables:', tables);
} finally {
  geoPackage.close();
}

create()

Creates a new, empty GeoPackage. In Node.js, a .gpkg file is written to the supplied path. In the browser (or when no path is given), an in-memory GeoPackage is created.
static async create(gppath?: string, name?: string): Promise<GeoPackage>
gppath
string
File path where the new .gpkg file should be created (Node.js only). The parent directory is created if it does not already exist. Omit or pass undefined to create an in-memory GeoPackage.
name
string
Optional name for the GeoPackage instance. Defaults to the basename of gppath, or 'geopackage' for in-memory instances.
Promise<GeoPackage>
Promise<GeoPackage>
Resolves with a newly created GeoPackage instance with the minimum required internal tables already initialised.
Errors thrown
  • GeoPackageException: 'Invalid GeoPackage' — the supplied path does not use a valid GeoPackage file extension.
  • GeoPackageException: 'Unable to initialize canvas.' — canvas adapter initialisation failed.
  • GeoPackageException: 'Unable to create GeoPackage.' — the file could not be created or the SQLite connection failed.
Create a new file on disk (Node.js)
import { GeoPackageManager } from '@ngageoint/geopackage';

const geoPackage = await GeoPackageManager.create('/output/my-data.gpkg');
try {
  // Add feature tables, tile tables, etc.
  console.log('Created:', geoPackage.getName());
} finally {
  geoPackage.close();
}
Create an in-memory GeoPackage
import { GeoPackageManager } from '@ngageoint/geopackage';

const geoPackage = await GeoPackageManager.create();
try {
  // Build the GeoPackage in memory, then export
  const bytes = await geoPackage.export();
  // bytes is a Uint8Array ready to save or transmit
} finally {
  geoPackage.close();
}
Always call geoPackage.close() when you are done to release the underlying SQLite connection. Using a try / finally block is the recommended pattern.

Build docs developers (and LLMs) love