gdal/
lib.rs

1#![crate_name = "gdal"]
2#![crate_type = "lib"]
3// Document all features on docs.rs
4#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5#![doc(test(attr(deny(warnings), allow(dead_code, unused_variables))))]
6
7//! # GDAL
8//! [GDAL](http://gdal.org/) is a translator and processing library for various raster and vector geospatial data formats.
9//!
10//! This crate provides safe, idiomatic [Rust](http://www.rust-lang.org/) bindings for GDAL.
11//!
12//! ## Capabilities
13//!
14//! GDAL is an incredibly powerful library. For a general understanding of its capabilities,
15//! a good place to get started is the [GDAL User-oriented documentation](https://gdal.org/user/index.html).
16//! These features include:
17//!
18//! * Opening raster and vector file formats for reading/writing
19//! * Translating between file formats
20//! * Reading and writing metadata in raster and vector datasets
21//! * Accessing raster bands and their metadata
22//! * Reading and writing geospatial coordinate system and projection values
23//! * Warping (resampling and re-projecting) between coordinate systems
24//!
25//! ## Usage
26//!
27//! This crate provides high-level, idiomatic Rust bindings for GDAL.
28//! To do that, it uses [`gdal-sys`](gdal-sys) internally, a low-level interface to the GDAL C library, which is generated using [`bindgen`](https://rust-lang.github.io/rust-bindgen/).
29//! Using the `gdal-sys` crate directly is normally not needed, but it can be useful in order to call APIs that have not yet been exposed in `gdal`.
30//!
31//! ## Version support
32//!
33//! As a general rule, only GDAL versions in Ubuntu LTS-1 (previous LTS version, that is, GDAL 3.4 in 22.04 at this moment) are supported.
34//! `gdal-sys` might support earlier versions using the `bindgen` feature flag, but `gdal` does not.
35//!
36//! Building this crate assumes a compatible version of GDAL is installed with the corresponding header files and shared libraries.
37//! This repository includes pre-generated bindings for GDAL 3.4 through 3.10 (see the `gdal-sys/prebuilt-bindings` directory).
38//! If you're compiling against another version of GDAL, you can enable the `bindgen` feature flag to have the bindings generated on the fly.
39//!
40//! ## Show Me Code!
41//!
42//! To get you started with GDAL (without having to read the whole manual!),
43//! take a look at the examples in the [`raster`](raster#example) and [`vector`](vector#example) modules,
44//! but for the maximally impatient, here you go:
45//!
46//! ```rust, no_run
47//! use gdal::Dataset;
48//! # fn main() -> gdal::errors::Result<()> {
49//! let ds = Dataset::open("fixtures/m_3607824_se_17_1_20160620_sub.tif")?;
50//! println!("This {} is in '{}' and has {} bands.", ds.driver().long_name(), ds.spatial_ref()?.name().unwrap(), ds.raster_count());
51//! # Ok(())
52//! # }
53//! ```
54//! ```text
55//! This GeoTIFF is in 'NAD83 / UTM zone 17N' and has 4 bands.
56//! ```
57//!
58//! ## Data Model
59//!
60//! At the top level, GDAL uses the same data model to access both vector and raster data sets.
61//! There are several shared data model constructs at this level, but the first ones to become
62//! familiar with are [`Driver`], [`Dataset`], and [`Metadata`].
63//! These provide the general access points to [`raster`]- and [`vector`]-specific constructs.
64//!
65//! ### Driver
66//!
67//! One of GDAL's major strengths is the vast number of data formats it's able to work with.
68//! The GDAL Manual has a full list of available [raster](https://gdal.org/drivers/raster/index.html)
69//! and [vector](https://gdal.org/drivers/vector/index.html) drivers.
70//!
71//! The [`Driver` API][Driver] provides the requisite access points for working GDAL's drivers.
72//!
73//! ### Dataset
74//!
75//! [`Dataset`] is the top-level container for accessing all data within a data set, whether raster or vector.
76//! Some methods and traits on `Dataset` are shared between raster and vector datasets,
77//! and (due to historical reasons) some associated functions are only applicable to one context or the other.
78//! The [`raster`] and [`vector`] modules cover these specifics.
79//!
80//! ### Metadata
81//!
82//! Metadata in GDAL takes a number of forms, some of which are specific to purpose
83//! (e.g. pixel interpretation, spatial reference system),
84//! and other more general-purpose (e.g. acquisition date-time). The former will be covered in
85//! relevant sections of the [`raster`] and [`vector`] modules, and the general-purpose data model
86//! in the [`Metadata`] API.
87//!
88//! ### Raster Data
89//!
90//! A raster `Dataset` has a `size` (`cols`,`rows`), an ordered sequence of [`RasterBand`](raster::RasterBand)s, geospatial
91//! metadata, and general-purpose [`Metadata`], common to all the bands.
92//!
93//! Each `RasterBand` contains a buffer of pixels (a.k.a. _cells_), a _no-data_ value, and other metadata.
94//!
95//! The [`raster`] module covers these concepts in more detail.
96//!
97//! ### Vector Data
98//!
99//! A vector `Dataset` contains a sequence of one or more [`Layer`](vector::Layer)s, geospatial metadata,
100//! and general-purpose [`Metadata`], common to all the layers.
101//! Each `Layer` in turn contains zero or more [`Feature`](vector::Feature)s, each of which contains  a `geometry`
102//! and set of fields.
103//!
104//! The [`vector`] module covers these concepts in more detail.
105
106pub use version::version_info;
107
108pub mod config;
109pub mod cpl;
110mod dataset;
111mod driver;
112pub mod errors;
113mod gcp;
114mod gdal_major_object;
115mod geo_transform;
116mod metadata;
117mod options;
118pub mod programs;
119pub mod raster;
120pub mod spatial_ref;
121#[cfg(test)]
122pub mod test_utils;
123mod utils;
124pub mod vector;
125pub mod version;
126pub mod vsi;
127
128pub use dataset::Dataset;
129pub use geo_transform::{GeoTransform, GeoTransformEx};
130pub use options::{DatasetOptions, GdalOpenFlags};
131
132pub use driver::{Driver, DriverManager, DriverType};
133pub use gcp::{Gcp, GcpRef};
134#[cfg(any(major_ge_4, all(major_is_3, minor_ge_6)))]
135pub use gdal_sys::ArrowArrayStream;
136pub use metadata::{Metadata, MetadataEntry};
137
138#[cfg(test)]
139fn assert_almost_eq(a: f64, b: f64) {
140    let f: f64 = a / b;
141    assert!(f < 1.00001);
142    assert!(f > 0.99999);
143}