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 ContainsPredicate,
238 // Geometric types (from oxigdal-core)
239 Coordinate,
240 DistanceMethod,
241
242 IntersectsPredicate,
243 IssueType,
244 LineString,
245 MultiPolygon,
246 Point,
247 Polygon,
248
249 SegmentIntersection,
250
251 Severity,
252 SimplifyMethod,
253
254 TouchesPredicate,
255
256 ValidationIssue,
257 // Area operations
258 area,
259 area_multipolygon,
260 area_polygon,
261 // Buffer operations
262 buffer_linestring,
263 buffer_point,
264 buffer_polygon,
265 // Union operations
266 cascaded_union,
267 // Centroid operations
268 centroid,
269 centroid_collection,
270 centroid_linestring,
271 centroid_multilinestring,
272 centroid_multipoint,
273 centroid_multipolygon,
274 centroid_point,
275 centroid_polygon,
276
277 // Difference operations
278 clip_to_box,
279 // Advanced modules
280 clustering,
281 // Spatial predicates (contains, intersects, etc.)
282 contains,
283 convex_hull,
284 delaunay,
285 difference_polygon,
286 difference_polygons,
287 disjoint,
288 // Distance operations
289 distance_point_to_linestring,
290 distance_point_to_point,
291 distance_point_to_polygon,
292 erase_small_holes,
293 // Intersection operations
294 intersect_linestrings,
295 intersect_linestrings_sweep,
296 intersect_polygons,
297 intersect_segment_segment,
298 intersects,
299 is_clockwise,
300 is_counter_clockwise,
301 merge_polygons,
302 network,
303 point_in_polygon,
304 point_in_polygon_or_boundary,
305 point_on_polygon_boundary,
306 point_strictly_inside_polygon,
307 // Simplification operations
308 simplify_linestring,
309 simplify_linestring_dp,
310 simplify_polygon,
311 spatial_join,
312 symmetric_difference,
313
314 topology,
315 touches,
316 union_polygon,
317 union_polygons,
318
319 // Validation operations
320 validate_geometry,
321 validate_linestring,
322 validate_polygon,
323 voronoi,
324 within,
325};
326
327/// Crate version
328pub const VERSION: &str = env!("CARGO_PKG_VERSION");
329
330/// Crate name
331pub const NAME: &str = env!("CARGO_PKG_NAME");
332
333#[cfg(test)]
334mod tests {
335 use super::*;
336
337 #[test]
338 fn test_version() {
339 assert!(!VERSION.is_empty());
340 assert_eq!(NAME, "oxigdal-algorithms");
341 }
342}