oxigdal_drivers_advanced/lib.rs
1//! OxiGDAL Advanced Format Drivers
2//!
3//! This crate provides advanced geospatial format drivers for OxiGDAL:
4//! - JPEG2000 (JP2) - Pure Rust JPEG2000 codec with GeoJP2 support
5//! - GeoPackage (GPKG) - SQLite-based vector and raster storage
6//! - KML/KMZ - Keyhole Markup Language for Google Earth
7//! - GML - Geography Markup Language (OGC standard)
8//!
9//! # Features
10//!
11//! - `jpeg2000` - JPEG2000 format support (enabled by default)
12//! - `geopackage` - GeoPackage format support (enabled by default)
13//! - `kml` - KML/KMZ format support (enabled by default)
14//! - `gml` - GML format support (enabled by default)
15//! - `async` - Async I/O support (optional)
16//!
17//! # Examples
18//!
19//! ## Reading JPEG2000
20//!
21//! ```no_run
22//! use oxigdal_drivers_advanced::jp2;
23//! use std::fs::File;
24//!
25//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
26//! let file = File::open("image.jp2")?;
27//! let image = jp2::read_jp2(file)?;
28//! println!("Dimensions: {}x{}", image.width, image.height);
29//! # Ok(())
30//! # }
31//! ```
32//!
33//! ## Reading GeoPackage
34//!
35//! ```no_run
36//! use oxigdal_drivers_advanced::gpkg::GeoPackage;
37//!
38//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
39//! let gpkg = GeoPackage::open("data.gpkg")?;
40//! let tables = gpkg.feature_tables()?;
41//! println!("Feature tables: {:?}", tables);
42//! # Ok(())
43//! # }
44//! ```
45//!
46//! ## Reading KML
47//!
48//! ```no_run
49//! use oxigdal_drivers_advanced::kml;
50//! use std::io::BufReader;
51//! use std::fs::File;
52//!
53//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
54//! let file = BufReader::new(File::open("placemarks.kml")?);
55//! let doc = kml::read_kml(file)?;
56//! println!("Placemarks: {}", doc.placemark_count());
57//! # Ok(())
58//! # }
59//! ```
60//!
61//! ## Reading GML
62//!
63//! ```no_run
64//! use oxigdal_drivers_advanced::gml;
65//! use std::io::BufReader;
66//! use std::fs::File;
67//!
68//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
69//! let file = BufReader::new(File::open("features.gml")?);
70//! let collection = gml::read_gml(file)?;
71//! println!("Features: {}", collection.len());
72//! # Ok(())
73//! # }
74//! ```
75
76#![deny(missing_docs)]
77#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::panic))]
78
79pub mod error;
80
81#[cfg(feature = "jpeg2000")]
82pub mod jp2;
83
84#[cfg(feature = "geopackage")]
85pub mod gpkg;
86
87#[cfg(feature = "kml")]
88pub mod kml;
89
90#[cfg(feature = "kml")]
91pub mod kmz;
92
93#[cfg(feature = "gml")]
94pub mod gml;
95
96pub use error::{Error, Result};
97
98/// Library version.
99pub const VERSION: &str = env!("CARGO_PKG_VERSION");
100
101/// Check if a format is supported based on file extension.
102pub fn is_supported(extension: &str) -> bool {
103 match extension.to_lowercase().as_str() {
104 #[cfg(feature = "jpeg2000")]
105 "jp2" | "j2k" | "jpf" | "jpx" => true,
106 #[cfg(feature = "geopackage")]
107 "gpkg" => true,
108 #[cfg(feature = "kml")]
109 "kml" | "kmz" => true,
110 #[cfg(feature = "gml")]
111 "gml" | "xml" => true,
112 _ => false,
113 }
114}
115
116/// Get list of supported format extensions.
117pub fn supported_extensions() -> Vec<&'static str> {
118 let mut extensions = Vec::new();
119
120 #[cfg(feature = "jpeg2000")]
121 {
122 extensions.extend_from_slice(&["jp2", "j2k", "jpf", "jpx"]);
123 }
124
125 #[cfg(feature = "geopackage")]
126 {
127 extensions.push("gpkg");
128 }
129
130 #[cfg(feature = "kml")]
131 {
132 extensions.extend_from_slice(&["kml", "kmz"]);
133 }
134
135 #[cfg(feature = "gml")]
136 {
137 extensions.extend_from_slice(&["gml", "xml"]);
138 }
139
140 extensions
141}
142
143#[cfg(test)]
144mod tests {
145 use super::*;
146
147 #[test]
148 fn test_version() {
149 assert!(!VERSION.is_empty());
150 }
151
152 #[test]
153 fn test_supported_extensions() {
154 let extensions = supported_extensions();
155 assert!(!extensions.is_empty());
156
157 #[cfg(feature = "jpeg2000")]
158 assert!(extensions.contains(&"jp2"));
159
160 #[cfg(feature = "geopackage")]
161 assert!(extensions.contains(&"gpkg"));
162
163 #[cfg(feature = "kml")]
164 assert!(extensions.contains(&"kml"));
165
166 #[cfg(feature = "gml")]
167 assert!(extensions.contains(&"gml"));
168 }
169
170 #[test]
171 fn test_is_supported() {
172 #[cfg(feature = "jpeg2000")]
173 {
174 assert!(is_supported("jp2"));
175 assert!(is_supported("JP2"));
176 assert!(is_supported("j2k"));
177 }
178
179 #[cfg(feature = "geopackage")]
180 assert!(is_supported("gpkg"));
181
182 #[cfg(feature = "kml")]
183 {
184 assert!(is_supported("kml"));
185 assert!(is_supported("kmz"));
186 }
187
188 #[cfg(feature = "gml")]
189 assert!(is_supported("gml"));
190
191 assert!(!is_supported("txt"));
192 assert!(!is_supported("unknown"));
193 }
194}