geopackage-ts
    Preparing search index...

    Class GeoPackageManager

    Factory class for creating, opening, and validating GeoPackage databases.

    GeoPackageManager provides static methods to manage the lifecycle of GeoPackage instances. It supports opening existing GeoPackage files (from disk or in-memory buffers), creating new GeoPackage databases (on disk or in memory), and validating that a file conforms to the GeoPackage specification.

    import { GeoPackageManager } from 'geopackage-ts';

    // Create a new GeoPackage on disk
    const gpkg = GeoPackageManager.create('/tmp/example.gpkg');

    // Open an existing GeoPackage
    const existing = GeoPackageManager.open('/tmp/example.gpkg');

    // Validate a GeoPackage file
    const result = GeoPackageManager.validate('/tmp/example.gpkg');
    console.log(result.valid); // true
    Index

    Constructors

    Methods

    • Creates a new GeoPackage database file on disk.

      This method creates the file (and any missing parent directories), sets the required GeoPackage application ID and user version, creates the mandatory tables (gpkg_spatial_ref_sys, gpkg_contents, etc.), and inserts the default Spatial Reference System definitions.

      Parameters

      • filePath: string

        The absolute or relative file path where the new GeoPackage should be created. The file extension should be .gpkg.

      Returns GeoPackage

      A GeoPackage instance connected to the newly created database.

      const gpkg = GeoPackageManager.create('/tmp/new-package.gpkg');
      // The file is now ready to accept feature tables, tile tables, etc.
    • Creates a new GeoPackage database entirely in memory.

      The resulting database is not backed by any file on disk. It is useful for temporary workloads, testing, or building a GeoPackage that will later be serialized to a buffer or written to disk.

      Like GeoPackageManager.create, this method initialises the required application ID, user version, mandatory tables, and default Spatial Reference System definitions.

      Returns GeoPackage

      A GeoPackage instance connected to an in-memory database.

      const gpkg = GeoPackageManager.createInMemory();
      // Work with the GeoPackage in memory
    • Opens an existing GeoPackage from a file path or an in-memory buffer.

      When a file path is provided, the method verifies that the file exists and has a valid GeoPackage extension (.gpkg or .gpkx) before opening it. When a Buffer is provided, the GeoPackage is opened directly from memory.

      Parameters

      • pathOrBuffer: string | Buffer<ArrayBufferLike>

        The absolute or relative path to a .gpkg / .gpkx file, or a Buffer containing the raw GeoPackage bytes.

      Returns GeoPackage

      A GeoPackage instance connected to the opened database.

      If the file does not exist at the given path.

      If the file extension is not .gpkg or .gpkx.

      // Open from a file path
      const gpkg = GeoPackageManager.open('./data/countries.gpkg');

      // Open from a buffer (e.g., fetched over the network)
      const buffer = fs.readFileSync('./data/countries.gpkg');
      const gpkg = GeoPackageManager.open(buffer);
    • Validates whether a file on disk is a well-formed GeoPackage.

      The validation checks include:

      • The file exists on disk.
      • The file extension is .gpkg or .gpkx.
      • The SQLite application_id matches the GeoPackage specification (0x47504B47 for GPKG or 0x47503130 for GP10).
      • The required gpkg_spatial_ref_sys table is present.
      • The required gpkg_contents table is present.

      Parameters

      • filePath: string

        The absolute or relative path to the file to validate.

      Returns ValidationResult

      A ValidationResult object containing a valid boolean and an errors array describing any issues found.

      const result = GeoPackageManager.validate('./data/countries.gpkg');
      if (!result.valid) {
      console.error('Validation errors:', result.errors);
      }