Skip to main content

Crate geopackage_core

Crate geopackage_core 

Source
Expand description

The parts of the OGC GeoPackage format that don’t need a database.

This crate contains the geometry codec, table definitions and validation rules of GeoPackage 1.4, with no SQLite dependency. Most users want the geopackage crate, which builds the SQLite container on top of this one. Use this crate directly for format code without SQLite: in a fuzz target, for example, or another GeoPackage implementation.

§Modules

  • gpb: The GeoPackage Binary (GPB) geometry header codec
  • geometry: A parsed geometry view (GpbGeometry), and GPB encoders for geometry objects and existing ISO WKB
  • curve: Envelopes read directly from ISO WKB, including exact extents for circular arcs
  • types: Column and geometry types (spec Table 1, Annex G)
  • datetime: DATE and DATETIME parsing, strict or lenient, with calendar validation and epoch conversion
  • ddl: CREATE TABLE statements and the required gpkg_spatial_ref_sys rows
  • srs: A subset of EPSG WKT1 definitions for gpkg_spatial_ref_sys
  • triggers: RTree spatial index tables and triggers, by spec version
  • tiles: Tile pyramid table definitions and the tile matrix model
  • coverage: Payload rules for tiled gridded coverages, checked from the TIFF or PNG header
  • schema: Column descriptions and value constraints from the gpkg_schema extension (Annex F.9)
  • metadata: Metadata records and references from the gpkg_metadata extension (Annex F.8)
  • related: Relationships from the Related Tables Extension (OGC 18-000)
  • version: application_id and user_version handling
  • ident: SQL identifier quoting

SQL is copied verbatim from the spec’s Annex C (“Table Definition SQL”) and Annex F.3 (“R-tree Spatial Indexes”).

§Example

Encode a geometry as a GPB blob and parse it back:

use geopackage_core::GpbGeometry;
use geopackage_core::geometry::encode_gpb;

let point = geo_types::Point::new(-6.26, 53.35);
let (blob, envelope) = encode_gpb(&point, 4326)?;
assert_eq!(envelope, Some([-6.26, -6.26, 53.35, 53.35]));

let parsed = GpbGeometry::parse(&blob)?;
assert_eq!(parsed.header().srs_id, 4326);
assert_eq!(parsed.xy_envelope(), envelope);

§Cargo features

  • geo-types (default): Enables GpbGeometry::to_geo, which converts a parsed geometry to a geo-types geometry. The geo_traits implementation doesn’t need it

§Untrusted input

GpbGeometry parses WKB with the wkb crate. Its 0.9.2 reader allocates based on element counts read from the blob without checking them against the blob’s length, so a malformed geometry can trigger a multi-gigabyte allocation. Until this is fixed upstream in georust/wkb, don’t parse geometries from untrusted sources.

Re-exports§

pub use geometry::GeometryError;
pub use geometry::GpbGeometry;
pub use gpb::Envelope;
pub use gpb::GpbError;
pub use gpb::GpbHeader;
pub use srs::SrsDefinition;
pub use tiles::TileCoord;
pub use tiles::TileError;
pub use tiles::TileFormat;
pub use tiles::TileMatrix;
pub use tiles::TileMatrixSet;
pub use types::ColumnType;
pub use types::GeometryType;
pub use types::GeometryTypeSet;
pub use types::ZmFlag;
pub use version::GpkgVersion;

Modules§

coverage
The payload profile of the tiled gridded coverage extension (OGC 17-066r2, version 1.1).
curve
XY envelopes computed directly from ISO WKB bytes, curve types included.
datetime
DATE / DATETIME column value parsing and formatting.
ddl
Normative table definition SQL (spec Annex C) and required seed rows.
extensions
Registered extension names (Annex F) and the scope values a gpkg_extensions row may take.
geometry
Lazy geometry wrapper over a GeoPackage Binary (GPB) blob.
gpb
GeoPackage Binary (GPB) header codec.
ident
SQL identifier quoting for SQLite.
metadata
The gpkg_metadata extension’s model (Annex F.8): metadata records and what they are attached to.
related
The Related Tables Extension’s model (OGC 18-000): relationships between a base table and a table of related content, through a mapping table.
schema
The gpkg_schema extension’s model (Annex F.9): column descriptions and the constraints on their values.
srs
Spatial reference system definitions: a vendored EPSG subset.
tiles
Tile pyramids: the user data table template (spec clause 2.2.8, Annex C), the tile matrix model, and the consistency rules a conforming pyramid satisfies.
triggers
RTree spatial index extension (gpkg_rtree_index, spec Annex F.3).
types
Column and geometry type vocabulary.
version
GeoPackage file identity: SQLite application_id and user_version pragmas.

Enums§

Error
Errors produced by this crate.