HeliosDB Geospatial Package - Complete Summary
HeliosDB Geospatial Package - Complete Summary
Package Overview
Package Name: heliosdb-geospatial
Version: 3.0.0
Purpose: PostGIS-compatible geospatial data types and functions for HeliosDB v3.0
Package Structure
heliosdb-geospatial/├── Cargo.toml # Package configuration and dependencies├── README.md # User documentation├── PACKAGE_SUMMARY.md # This file│├── src/│ ├── lib.rs # Package entry point and public API│ ├── error.rs # Error types and Result alias│ ├── types.rs # Geometry type definitions│ ├── functions.rs # PostGIS-compatible ST_* functions│ ├── rtree.rs # R-tree spatial index implementation│ ├── wkt.rs # WKT parsing and formatting│ ├── wkb.rs # WKB encoding and decoding│ └── projections.rs # Coordinate transformations (SRID support)│├── examples/│ ├── basic_usage.rs # Basic geometry operations│ ├── spatial_index.rs # R-tree indexing and queries│ ├── wkt_wkb.rs # Text and binary formats│ └── projections.rs # Coordinate transformations│├── tests/│ └── integration_test.rs # Comprehensive integration tests│└── benches/ └── spatial_operations.rs # Performance benchmarksCore Components
1. Cargo.toml
Lines: 60 Dependencies:
geo,geo-types- Core geometry algorithmsrstar- R-tree spatial indexingproj- Coordinate transformationswkt,wkb- Format supportserde- Serializationthiserror,anyhow- Error handlingbyteorder- Binary encoding
2. lib.rs (Package Entry Point)
Lines: 67 Exports:
- All geometry types (Point, LineString, Polygon, etc.)
- All spatial functions
- Spatial index types
- Error types
- Constants (WGS84_SRID, WEB_MERCATOR_SRID)
3. error.rs (Error Handling)
Lines: 50 Features:
GeospatialErrorenum with 11 error variantsResult<T>type alias- Auto-conversion from external error types
- Comprehensive error messages
4. types.rs (Geometry Types)
Lines: 350 Geometry Types:
Point- 2D point with optional SRIDLineString- Sequence of connected pointsPolygon- Exterior ring with optional holesMultiPoint- Collection of pointsMultiLineString- Collection of linestringsMultiPolygon- Collection of polygonsGeometryCollection- Heterogeneous collectionGeography- Spherical geometry type
Features:
- SRID support on all types
- Conversion to/from geo-types
- Serialization support
- Type accessors and mutators
5. functions.rs (Spatial Functions)
Lines: 450 Function Categories:
Measurement Functions (6)
st_distance- Euclidean distancest_distance_spheroid- Haversine distancest_length- Linear lengthst_area- Polygon areast_perimeter- Polygon perimeterhaversine_distance- Spherical distance helper
Spatial Relationships (7)
st_contains- Containment testst_within- Inverse containmentst_intersects- Intersection testst_disjoint- Disjoint testst_touches- Touch testst_overlaps- Overlap testst_equals- Equality test
Geometry Processing (7)
st_centroid- Calculate centroidst_envelope- Bounding boxst_convex_hull- Convex hullst_simplify- Douglas-Peucker simplificationst_simplify_preserve_topology- Visvalingam-Whyattst_buffer- Buffer generation- Various geometry constructors
Accessors (8)
st_x,st_y- Coordinate gettersst_npoints- Point countst_srid,st_set_srid- SRID managementst_geometry_type- Type namest_is_empty- Emptiness testst_is_valid- Validity test
Total: 30+ functions
6. rtree.rs (R-tree Spatial Index)
Lines: 350 Components:
SpatialObject- Indexed geometry wrapperSpatialIndex- Main R-tree indexSpatialIndexBuilder- Bulk loading builderspatial_join- Join operation
Features:
- O(log n) insertion
- O(log n + k) bounding box queries
- K-Nearest Neighbor search
- KNN with distance limits
- Bulk loading optimization
- SRID validation
- Spatial join operations
7. wkt.rs (Well-Known Text)
Lines: 400 Functions:
parse_wkt- Parse WKT string to Geometryparse_wkt_with_srid- Parse with SRID prefixto_wkt- Format Geometry as WKT- Internal parsers for all geometry types
Supported Formats:
POINT(x y)LINESTRING(x1 y1, x2 y2, ...)POLYGON((x1 y1, ...), (hole1), ...)MULTIPOINT(x1 y1, ...)MULTILINESTRING((...),...)MULTIPOLYGON(((...)...),...)GEOMETRYCOLLECTION(...)SRID=4326;POINT(x y)
8. wkb.rs (Well-Known Binary)
Lines: 550 Components:
WKBTypeenum - Geometry type codesByteOrderenum - Endianness controlto_wkb- Encode to binaryfrom_wkb- Decode from binaryfrom_wkb_with_srid- Decode with SRID
Features:
- Big-endian and little-endian support
- Efficient binary encoding
- OGC WKB specification compliant
- All geometry types supported
9. projections.rs (Coordinate Transformations)
Lines: 350 Components:
ProjectionTransformer- Main transformer with cachetransform_to_wgs84- Helper for WGS84transform_to_web_mercator- Helper for Web Mercatorcalculate_bounds- Bounding box calculationget_center- Center point calculation
Supported SRIDs:
- 4326 (WGS84 - Geographic)
- 3857 (Web Mercator - Projected)
- 4269 (NAD83)
- 32601-32660 (UTM Northern Hemisphere)
- 32701-32760 (UTM Southern Hemisphere)
- 4258 (ETRS89)
- 27700 (British National Grid)
- Any EPSG code via PROJ library
Examples
1. basic_usage.rs
Lines: 150 Demonstrates:
- Point distance calculations
- LineString operations
- Polygon area and perimeter
- Spatial relationships
- Geometry processing
- Geographic distance (spheroid)
2. spatial_index.rs
Lines: 200 Demonstrates:
- Basic index operations
- Bounding box queries
- K-Nearest Neighbor search
- Bulk loading
- Spatial join operations
3. wkt_wkb.rs
Lines: 180 Demonstrates:
- WKT parsing and formatting
- WKT with SRID
- Complex geometries
- WKB encoding/decoding
- Byte order handling
- WKB with SRID
4. projections.rs
Lines: 160 Demonstrates:
- WGS84 to Web Mercator
- Web Mercator to WGS84
- Polygon transformation
- Bounds calculation
- Center point calculation
- Multiple transformations
Tests
integration_test.rs
Lines: 450 Test Coverage:
- All geometry types
- All spatial functions
- Spatial index operations
- WKT parsing and formatting
- WKB encoding and decoding
- Coordinate transformations
- SRID validation
- Geography type
- Error handling
Total Tests: 30+
Benchmarks
spatial_operations.rs
Lines: 250 Benchmarks:
- Distance calculations (Euclidean, Spheroid)
- Area and perimeter
- Spatial relationships
- R-tree operations (insert, bulk load, query)
- WKT parsing and formatting
- WKB encoding and decoding
Benchmark Groups: 6
Performance Characteristics
R-tree Index
- Insertion: O(log n)
- Bounding Box Query: O(log n + k) where k = results
- KNN Search: O(k log n)
- Bulk Loading: O(n log n) with optimized structure
Spatial Functions
- Distance: O(1) for points, O(n) for complex geometries
- Contains: O(log n) average case
- Intersects: O(n) for polygon-polygon
- Centroid: O(n) where n = vertices
- Buffer: O(n * segments)
Format Conversion
- WKT Parsing: O(n) where n = string length
- WKT Formatting: O(n) where n = coordinates
- WKB Encoding: O(n) where n = coordinates
- WKB Decoding: O(n) where n = bytes
Features Flags
default: Enables rtree and projectionsrtree: R-tree spatial indexingprojections: Coordinate transformationsserde: Serialization support
Total Code Statistics
| Component | Files | Lines | Purpose |
|---|---|---|---|
| Core Source | 8 | ~2,500 | Main implementation |
| Examples | 4 | ~650 | Usage demonstrations |
| Tests | 1 | ~450 | Integration testing |
| Benchmarks | 1 | ~250 | Performance testing |
| Documentation | 2 | ~400 | User guides |
| Total | 16 | ~4,250 | Complete package |
Key Features Summary
Geometry Types: 7 OGC-compliant types Spatial Functions: 30+ PostGIS-compatible functions Spatial Indexing: R-tree with KNN search Format Support: WKT and WKB Projections: Full SRID transformation support Geography: Spherical calculations Performance: Optimized algorithms and bulk loading Testing: Comprehensive test coverage Examples: 4 detailed examples Benchmarks: Performance tracking
Usage Example
use heliosdb_geospatial::{Point, Geometry, functions::*};
// Create points with SRIDlet sf = Point::new(-122.4194, 37.7749, Some(4326));let la = Point::new(-118.2437, 34.0522, Some(4326));
// Calculate spherical distancelet distance = st_distance_spheroid( &Geometry::Point(sf), &Geometry::Point(la)).unwrap();
println!("Distance: {} km", distance / 1000.0);Integration with HeliosDB
This package provides the foundation for:
- Geospatial column types (GEOMETRY, GEOGRAPHY)
- Spatial indexing strategies
- Geospatial query functions
- Spatial join operations
- GIS data import/export
License
MIT OR Apache-2.0