Creates a new GeoPackage instance.
The logical name of the GeoPackage (e.g. file name without extension).
The file-system path to the .gpkg file, or null for in-memory databases.
An already-initialised GeoPackageConnection to the SQLite database.
ReadonlynameThe logical name of this GeoPackage, typically derived from the file name
(without the .gpkg extension).
ReadonlypathThe file-system path of the GeoPackage, or null when the database resides
in memory or was opened from a buffer.
Closes the underlying database connection and releases all associated resources.
After calling this method the GeoPackage instance should no longer be used. Any subsequent calls to methods that access the database will fail.
Creates a new attribute (non-spatial) table in the GeoPackage.
This method performs the following steps:
id primary key column and any
additional user-specified columns.gpkg_contents to register the table with data_type = 'attributes'.Attribute tables have no geometry column and no SRS association. Their bounding box
fields in gpkg_contents are set to null.
The name for the new attribute table.
Optional array of extra UserColumn definitions to
include beyond the id column. Column indices are automatically reassigned starting
at 1. Defaults to [].
import { GeoPackageDataType } from 'geopackage-ts';
geoPackage.createAttributeTable('metadata', [
{
index: 0,
name: 'key',
dataType: GeoPackageDataType.TEXT,
notNull: true,
defaultValue: null,
primaryKey: false,
autoincrement: false,
unique: true,
},
{
index: 1,
name: 'value',
dataType: GeoPackageDataType.TEXT,
notNull: false,
defaultValue: null,
primaryKey: false,
autoincrement: false,
unique: false,
},
]);
Creates a new feature (vector) table in the GeoPackage.
This method performs the following steps:
gpkg_geometry_columns metadata table exists.id primary key
column, a geometry BLOB column, and any additional user-specified columns.gpkg_contents to register the table.gpkg_geometry_columns to describe the geometry column.The name for the new feature table.
The name of the column that will store geometry BLOBs
(e.g. 'geom' or 'geometry').
The OGC geometry type name (e.g. 'POINT', 'LINESTRING',
'POLYGON', 'GEOMETRY').
The Spatial Reference System identifier (must already exist in
gpkg_spatial_ref_sys). Common values: 4326 (WGS 84), 3857 (Web Mercator).
Optional array of extra UserColumn definitions to
include in the table beyond the id and geometry columns. Column indices are
automatically reassigned starting at 2. Defaults to [].
Optionalbbox: BoundingBoxOptional bounding box for the contents metadata. When omitted, the
bounding box fields in gpkg_contents are set to null.
The FeatureTable definition describing the newly created table.
import { GeoPackageDataType } from 'geopackage-ts';
const featureTable = geoPackage.createFeatureTable(
'buildings',
'geom',
'POLYGON',
4326,
[
{
index: 0,
name: 'name',
dataType: GeoPackageDataType.TEXT,
notNull: false,
defaultValue: null,
primaryKey: false,
autoincrement: false,
unique: false,
},
],
{ minX: -180, minY: -90, maxX: 180, maxY: 90 },
);
Creates a new tile (raster) table in the GeoPackage.
This method performs the following steps:
gpkg_tile_matrix_set and gpkg_tile_matrix metadata tables exist.id, zoom_level, tile_column,
tile_row, and tile_data.gpkg_contents to register the table.gpkg_tile_matrix_set with the bounding box and SRS.gpkg_tile_matrix for each provided tile matrix definition.The name for the new tile table.
The Spatial Reference System identifier for the tile data.
Common values: 3857 (Web Mercator), 4326 (WGS 84).
The bounding box of the tile data, expressed in coordinates of the specified SRS.
Optional array of TileMatrix definitions describing the
zoom levels, tile grid dimensions, and pixel sizes. The table_name field of each
entry is automatically set to the provided tableName. Defaults to [].
geoPackage.createTileTable('imagery', 3857, {
minX: -20037508.342789244,
minY: -20037508.342789244,
maxX: 20037508.342789244,
maxY: 20037508.342789244,
}, [
{
table_name: '',
zoom_level: 0,
matrix_width: 1,
matrix_height: 1,
tile_width: 256,
tile_height: 256,
pixel_x_size: 156543.03392804097,
pixel_y_size: 156543.03392804097,
},
]);
Serialises the entire GeoPackage database to an in-memory buffer.
This is useful for saving an in-memory GeoPackage to disk, sending it over the network, or creating a snapshot of the current database state.
A Buffer containing the complete SQLite database file.
Retrieves all Spatial Reference System definitions from the GeoPackage.
An array of all SpatialReferenceSystem records in gpkg_spatial_ref_sys.
Creates an AttributeDao for querying and manipulating rows in an existing attribute (non-spatial) table.
The name of the attribute table. Must already exist in the GeoPackage.
An AttributeDao bound to the specified table.
Retrieves gpkg_contents rows filtered by data type.
The content data type to filter by ('features', 'tiles', or 'attributes').
An array of Contents records matching the specified data type.
Returns the underlying GeoPackageConnection for advanced or low-level database operations.
Use this when you need to execute raw SQL or access connection features not exposed through the high-level GeoPackage API.
The GeoPackageConnection instance backing this GeoPackage.
Creates a FeatureDao for querying and manipulating rows in an existing feature table.
The name of the feature table. Must already exist and have a
corresponding entry in gpkg_geometry_columns.
A FeatureDao bound to the specified table.
GeoPackageError If no geometry column metadata is found for the table.
Retrieves a Spatial Reference System definition by its identifier.
The srs_id value as defined in gpkg_spatial_ref_sys.
The matching SpatialReferenceSystem record, or undefined if not found.
Creates a TileDao for querying and manipulating tiles in an existing tile table.
The name of the tile table. Must already exist and have a
corresponding entry in gpkg_tile_matrix_set.
A TileDao bound to the specified table.
GeoPackageError If no tile matrix set metadata is found for the table.
Creates an RTree spatial index on the geometry column of a feature table.
Building a spatial index significantly improves the performance of bounding-box queries (e.g. FeatureDao.queryWithBoundingBox). The index is registered as a GeoPackage extension following the RTree Spatial Index specification.
The name of the feature table to index. Must have a corresponding
entry in gpkg_geometry_columns.
GeoPackageError If no geometry column metadata is found for the table.
Checks whether an RTree spatial index exists for a feature table.
The name of the feature table to check.
true if an RTree spatial index is present for the table's geometry column,
false otherwise (including when the table has no geometry column metadata).
Queries a feature table and returns all rows as GeoJSON Feature objects.
This is a convenience method that internally creates a FeatureDao and delegates to FeatureDao.queryForGeoJSON.
The name of the feature table to query.
An iterable iterator of GeoJSON GeoJSON.Feature objects.
GeoPackageError If no geometry column metadata is found for the table.
The primary class for interacting with a GeoPackage database.
A
GeoPackageinstance wraps an underlying SQLite database connection and provides high-level methods for reading and writing feature (vector), tile (raster), and attribute data according to the OGC GeoPackage specification.Instances are typically created via the static factory methods in the
GeoPackageManagerrather than by calling the constructor directly.Example