Skip to main content

oxigdal_algorithms/
lib.rs

1//! OxiGDAL Algorithms - High-Performance Raster and Vector Operations
2//!
3//! This crate provides production-ready geospatial algorithms for raster and vector processing,
4//! with a focus on performance, correctness, and Pure Rust implementation.
5//!
6//! # Features
7//!
8//! ## Resampling Algorithms
9//!
10//! - Nearest neighbor (fast, preserves exact values)
11//! - Bilinear interpolation (smooth, good for continuous data)
12//! - Bicubic interpolation (high quality, slower)
13//! - Lanczos resampling (highest quality, expensive)
14//!
15//! ## Raster Operations
16//!
17//! - Raster calculator (map algebra with expression evaluation)
18//! - Hillshade generation (3D terrain visualization)
19//! - Slope and aspect calculation (terrain analysis)
20//! - Reclassification (value mapping and binning)
21//! - Zonal statistics (aggregate statistics by zones)
22//!
23//! ## Vector Operations
24//!
25//! ### Geometric Operations
26//! - Buffer generation (fixed and variable distance, multiple cap/join styles)
27//! - Intersection (geometric intersection with sweep line algorithm)
28//! - Union (geometric union, cascaded union, convex hull)
29//! - Difference (geometric difference, symmetric difference, clip to box)
30//!
31//! ### Simplification
32//! - Douglas-Peucker simplification (perpendicular distance based)
33//! - Visvalingam-Whyatt simplification (area based)
34//! - Topology-preserving simplification
35//!
36//! ### Geometric Analysis
37//! - Centroid calculation (geometric and area-weighted, all geometry types)
38//! - Area calculation (planar and geodetic methods)
39//! - Distance measurement (Euclidean, Haversine, Vincenty)
40//!
41//! ### Spatial Predicates
42//! - Contains, Within (point-in-polygon tests)
43//! - Intersects, Disjoint (intersection tests)
44//! - Touches, Overlaps (boundary relationships)
45//!
46//! ### Validation
47//! - Geometry validation (OGC Simple Features compliance)
48//! - Self-intersection detection
49//! - Duplicate vertex detection
50//! - Ring orientation and closure checks
51//!
52//! ## SIMD Optimizations
53//!
54//! Many algorithms use SIMD instructions (when enabled) for maximum performance.
55//! Enable the `simd` feature for best performance.
56//!
57//! # Examples
58//!
59//! ## Raster Resampling
60//!
61//! ```
62//! use oxigdal_algorithms::resampling::{ResamplingMethod, Resampler};
63//! use oxigdal_core::buffer::RasterBuffer;
64//! use oxigdal_core::types::RasterDataType;
65//!
66//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
67//! // Create source raster
68//! let src = RasterBuffer::zeros(1000, 1000, RasterDataType::Float32);
69//!
70//! // Resample to half size using bilinear interpolation
71//! let resampler = Resampler::new(ResamplingMethod::Bilinear);
72//! let dst = resampler.resample(&src, 500, 500)?;
73//! # Ok(())
74//! # }
75//! ```
76//!
77//! ## Vector Operations
78//!
79//! ```
80//! use oxigdal_algorithms::{
81//!     Coordinate, LineString, Point, Polygon,
82//!     buffer_point, BufferOptions,
83//!     area, area_polygon, AreaMethod,
84//!     centroid_polygon, simplify_linestring, SimplifyMethod,
85//!     validate_polygon,
86//! };
87//!
88//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
89//! // Create a point and buffer it
90//! let point = Point::new(0.0, 0.0);
91//! let options = BufferOptions::default();
92//! let buffered = buffer_point(&point, 10.0, &options)?;
93//!
94//! // Calculate area of a polygon
95//! let coords = vec![
96//!     Coordinate::new_2d(0.0, 0.0),
97//!     Coordinate::new_2d(10.0, 0.0),
98//!     Coordinate::new_2d(10.0, 10.0),
99//!     Coordinate::new_2d(0.0, 10.0),
100//!     Coordinate::new_2d(0.0, 0.0),
101//! ];
102//! let exterior = LineString::new(coords)?;
103//! let polygon = Polygon::new(exterior, vec![])?;
104//! let area_value = area_polygon(&polygon, AreaMethod::Planar)?;
105//! # assert!((area_value - 100.0).abs() < 1e-10);
106//!
107//! // Simplify a linestring
108//! let line_coords = vec![
109//!     Coordinate::new_2d(0.0, 0.0),
110//!     Coordinate::new_2d(1.0, 0.1),
111//!     Coordinate::new_2d(2.0, -0.05),
112//!     Coordinate::new_2d(3.0, 0.0),
113//! ];
114//! let linestring = LineString::new(line_coords)?;
115//! let simplified = simplify_linestring(&linestring, 0.15, SimplifyMethod::DouglasPeucker)?;
116//!
117//! // Validate a polygon
118//! let issues = validate_polygon(&polygon)?;
119//! assert!(issues.is_empty()); // Valid square has no issues
120//! # Ok(())
121//! # }
122//! ```
123//!
124//! # Performance
125//!
126//! All algorithms are designed for production use with:
127//!
128//! - Zero-copy operations where possible
129//! - SIMD vectorization (x86_64 AVX2, ARM NEON)
130//! - Cache-friendly memory access patterns
131//! - Optional parallel processing via `rayon`
132//!
133//! # COOLJAPAN Policy Compliance
134//!
135//! - Pure Rust (no C/Fortran dependencies)
136//! - No `unwrap()` or `expect()` in production code
137//! - Comprehensive error handling
138//! - no_std compatible core algorithms (with `alloc`)
139
140#![cfg_attr(not(feature = "std"), no_std)]
141#![warn(clippy::all)]
142// Pedantic disabled to reduce noise - default clippy::all is sufficient
143// #![warn(clippy::pedantic)]
144#![deny(clippy::unwrap_used)]
145#![deny(clippy::panic)]
146#![allow(clippy::module_name_repetitions)]
147// Allow loop indexing patterns common in geospatial algorithms
148#![allow(clippy::needless_range_loop)]
149// Allow expect() for internal invariants that shouldn't fail
150#![allow(clippy::expect_used)]
151// Allow more arguments for complex geospatial operations
152#![allow(clippy::too_many_arguments)]
153// Allow manual implementations for clarity in algorithms
154#![allow(clippy::manual_memcpy)]
155#![allow(clippy::manual_div_ceil)]
156#![allow(clippy::manual_clamp)]
157// Allow dead code for internal algorithm structures
158#![allow(dead_code)]
159// Allow partial documentation for complex algorithm modules
160#![allow(missing_docs)]
161// Allow non-canonical partial_cmp for custom ordering
162#![allow(clippy::non_canonical_partial_ord_impl)]
163// Allow unused variables in algorithm code
164#![allow(unused_variables)]
165#![allow(unused_imports)]
166// Allow collapsible match for algorithm clarity
167#![allow(clippy::collapsible_match)]
168#![allow(clippy::collapsible_if)]
169// Allow manual_strip for path handling
170#![allow(clippy::manual_strip)]
171// Allow should_implement_trait for builder patterns
172#![allow(clippy::should_implement_trait)]
173// Allow method names that match trait names but with different signatures
174#![allow(clippy::wrong_self_convention)]
175// Allow iter_with_drain for performance patterns
176#![allow(clippy::iter_with_drain)]
177// Allow map_values for explicit iteration
178#![allow(clippy::iter_kv_map)]
179// Allow loop over option for clarity in algorithm code
180#![allow(for_loops_over_fallibles)]
181// Allow first element access with get(0)
182#![allow(clippy::get_first)]
183// Allow redundant closure for clarity
184#![allow(clippy::redundant_closure)]
185// Allow field assignment outside initializer
186#![allow(clippy::field_reassign_with_default)]
187// Allow manual iterator find implementations
188#![allow(clippy::manual_find)]
189// Allow identical blocks in if statements for algorithm clarity
190#![allow(clippy::if_same_then_else)]
191// Allow elided lifetime confusion
192#![allow(clippy::needless_lifetimes)]
193// Allow unused assignments for algorithm control flow
194#![allow(unused_assignments)]
195// Allow impls that can be derived (explicit implementations preferred)
196#![allow(clippy::derivable_impls)]
197// Allow explicit counter loop for clarity
198#![allow(clippy::explicit_counter_loop)]
199// Allow clone where from_ref could be used
200#![allow(clippy::clone_on_ref_ptr)]
201// Allow doc list item overindentation in complex formulas
202#![allow(clippy::doc_overindented_list_items)]
203// Allow useless vec for clarity in algorithm tests
204#![allow(clippy::useless_vec)]
205// Allow slice from ref pattern for geometry operations
206#![allow(clippy::assigning_clones)]
207
208pub mod error;
209pub mod raster;
210pub mod resampling;
211pub mod vector;
212
213#[cfg(feature = "simd")]
214pub mod simd;
215
216#[cfg(feature = "parallel")]
217pub mod parallel;
218
219#[cfg(feature = "dsl")]
220pub mod dsl;
221
222// Tutorial documentation
223pub mod tutorials;
224
225// Re-export commonly used items
226pub use error::{AlgorithmError, Result};
227pub use resampling::{Resampler, ResamplingMethod};
228
229// Re-export vector operations for convenience
230pub use vector::{
231    AreaMethod,
232
233    BufferCapStyle,
234    BufferJoinStyle,
235    BufferOptions,
236
237    // Clipping operations
238    ClipOperation,
239    ContainsPredicate,
240    // Geometric types (from oxigdal-core)
241    Coordinate,
242    DistanceMethod,
243
244    IntersectsPredicate,
245    IssueType,
246    LineString,
247    MultiPolygon,
248    Point,
249    Polygon,
250
251    SegmentIntersection,
252
253    Severity,
254    SimplifyMethod,
255
256    TopologySimplifyOptions,
257    TouchesPredicate,
258
259    ValidationIssue,
260    // Area operations
261    area,
262    area_multipolygon,
263    area_polygon,
264    // Buffer operations
265    buffer_linestring,
266    buffer_point,
267    buffer_polygon,
268    // Union operations
269    cascaded_union,
270    // Centroid operations
271    centroid,
272    centroid_collection,
273    centroid_linestring,
274    centroid_multilinestring,
275    centroid_multipoint,
276    centroid_multipolygon,
277    centroid_point,
278    centroid_polygon,
279
280    clip_multi,
281    clip_polygons,
282    // Difference operations
283    clip_to_box,
284    // Advanced modules
285    clustering,
286    // Spatial predicates (contains, intersects, etc.)
287    contains,
288    convex_hull,
289    delaunay,
290    difference_polygon,
291    difference_polygons,
292    disjoint,
293    // Distance operations
294    distance_point_to_linestring,
295    distance_point_to_point,
296    distance_point_to_polygon,
297    erase_small_holes,
298    // Intersection operations
299    intersect_linestrings,
300    intersect_linestrings_sweep,
301    intersect_polygons,
302    intersect_segment_segment,
303    intersects,
304    is_clockwise,
305    is_counter_clockwise,
306    merge_polygons,
307    network,
308    point_in_polygon,
309    point_in_polygon_or_boundary,
310    point_on_polygon_boundary,
311    point_strictly_inside_polygon,
312    // Simplification operations
313    simplify_linestring,
314    simplify_linestring_dp,
315    simplify_polygon,
316    // Topology-preserving simplification
317    simplify_topology,
318    simplify_topology_with_options,
319    spatial_join,
320    symmetric_difference,
321
322    topology,
323    touches,
324    union_polygon,
325    union_polygons,
326
327    // Validation operations
328    validate_geometry,
329    validate_linestring,
330    validate_polygon,
331    voronoi,
332    within,
333};
334
335/// Crate version
336pub const VERSION: &str = env!("CARGO_PKG_VERSION");
337
338/// Crate name
339pub const NAME: &str = env!("CARGO_PKG_NAME");
340
341#[cfg(test)]
342mod tests {
343    use super::*;
344
345    #[test]
346    fn test_version() {
347        assert!(!VERSION.is_empty());
348        assert_eq!(NAME, "oxigdal-algorithms");
349    }
350}