geopackage_core/lib.rs
1//! The parts of the [OGC GeoPackage](https://www.geopackage.org/spec140/)
2//! format that don't need a database.
3//!
4//! This crate contains the geometry codec, table definitions and validation
5//! rules of GeoPackage 1.4, with no SQLite dependency. Most users want the
6//! `geopackage` crate, which builds the SQLite container on top of this one.
7//! Use this crate directly for format code without SQLite: in a fuzz target,
8//! for example, or another GeoPackage implementation.
9//!
10//! # Modules
11//!
12//! - **[`gpb`]**: The GeoPackage Binary (GPB) geometry header codec
13//! - **[`geometry`]**: A parsed geometry view ([`GpbGeometry`]), and GPB
14//! encoders for geometry objects and existing ISO WKB
15//! - **[`curve`]**: Envelopes read directly from ISO WKB, including exact
16//! extents for circular arcs
17//! - **[`types`]**: Column and geometry types (spec Table 1, Annex G)
18//! - **[`datetime`]**: `DATE` and `DATETIME` parsing, strict or lenient, with
19//! calendar validation and epoch conversion
20//! - **[`ddl`]**: `CREATE TABLE` statements and the required
21//! `gpkg_spatial_ref_sys` rows
22//! - **[`srs`]**: A subset of EPSG WKT1 definitions for
23//! `gpkg_spatial_ref_sys`
24//! - **[`triggers`]**: RTree spatial index tables and triggers, by spec
25//! version
26//! - **[`tiles`]**: Tile pyramid table definitions and the tile matrix model
27//! - **[`coverage`]**: Payload rules for tiled gridded coverages, checked from
28//! the TIFF or PNG header
29//! - **[`schema`]**: Column descriptions and value constraints from the
30//! `gpkg_schema` extension (Annex F.9)
31//! - **[`metadata`]**: Metadata records and references from the
32//! `gpkg_metadata` extension (Annex F.8)
33//! - **[`related`]**: Relationships from the Related Tables Extension
34//! (OGC 18-000)
35//! - **[`version`]**: `application_id` and `user_version` handling
36//! - **[`ident`]**: SQL identifier quoting
37//!
38//! SQL is copied verbatim from the spec's Annex C ("Table Definition SQL") and
39//! Annex F.3 ("R-tree Spatial Indexes").
40//!
41//! # Example
42//!
43//! Encode a geometry as a GPB blob and parse it back:
44//!
45//! ```
46//! # #[cfg(feature = "geo-types")]
47//! # fn main() -> Result<(), geopackage_core::Error> {
48//! use geopackage_core::GpbGeometry;
49//! use geopackage_core::geometry::encode_gpb;
50//!
51//! let point = geo_types::Point::new(-6.26, 53.35);
52//! let (blob, envelope) = encode_gpb(&point, 4326)?;
53//! assert_eq!(envelope, Some([-6.26, -6.26, 53.35, 53.35]));
54//!
55//! let parsed = GpbGeometry::parse(&blob)?;
56//! assert_eq!(parsed.header().srs_id, 4326);
57//! assert_eq!(parsed.xy_envelope(), envelope);
58//! # Ok(()) }
59//! # #[cfg(not(feature = "geo-types"))]
60//! # fn main() {}
61//! ```
62//!
63//! # Cargo features
64//!
65//! - **`geo-types`** (default): Enables [`GpbGeometry::to_geo`], which converts
66//! a parsed geometry to a `geo-types` geometry. The [`geo_traits`]
67//! implementation doesn't need it
68
69// `unsafe_code = "forbid"` and `missing_docs = "warn"` come from the
70// workspace lints table (root Cargo.toml). This crate never uses `unsafe`; the
71// `geopackage-ffi` crate is the sole exception, and opts out of the workspace
72// lints rather than relaxing them here.
73
74mod error;
75
76pub mod coverage;
77pub mod curve;
78pub mod datetime;
79pub mod ddl;
80pub mod extensions;
81pub mod geometry;
82pub mod gpb;
83pub mod ident;
84pub mod metadata;
85pub mod related;
86pub mod schema;
87pub mod srs;
88pub mod tiles;
89pub mod triggers;
90pub mod types;
91pub mod version;
92
93pub use error::Error;
94pub use geometry::{GeometryError, GpbGeometry};
95pub use gpb::{Envelope, GpbError, GpbHeader};
96pub use srs::SrsDefinition;
97pub use tiles::{TileCoord, TileError, TileFormat, TileMatrix, TileMatrixSet};
98pub use types::{ColumnType, GeometryType, GeometryTypeSet, ZmFlag};
99pub use version::GpkgVersion;