spatio-types
Core spatial and temporal data types for the Spatio database.
This crate provides fundamental types for working with spatio-temporal data, built on top of the geo crate's geometric primitives. All types are serializable with Serde.
Installation
[]
= "0.1"
Optional Features
[]
# Enable GeoJSON support for serialization/deserialization
= { = "0.1", = ["geojson"] }
Types
Point Types
TemporalPoint- 2D point with timestampTemporalPoint3D- 3D point with timestamp and altitudePoint3d- 3D point with altitude
Polygon Types
PolygonDynamic- 2D polygon with dynamic metadataPolygon3D- 3D polygon with altitudePolygonDynamic3D- 3D polygon with dynamic metadata
Trajectory Types
Trajectory- Collection of 2D temporal points representing movementTrajectory3D- Collection of 3D temporal points with altitude
Bounding Box Types
BoundingBox2D- 2D rectangular boundsBoundingBox3D- 3D cuboid boundsTemporalBoundingBox2D- 2D bounds with time rangeTemporalBoundingBox3D- 3D bounds with time range
Examples
Temporal Points
use TemporalPoint;
use Point;
use SystemTime;
// Create a temporal point (location with timestamp)
let point = new; // NYC coordinates
let temporal_point = new;
println!;
3D Points
use Point3d;
// Create a 3D point with altitude
let drone_position = new;
println!;
Bounding Boxes
use BoundingBox2D;
use Point;
// Create a bounding box for Manhattan
let manhattan = new;
// Check if a point is within bounds
let empire_state = new;
assert!;
// Get the center point
let center = manhattan.center;
println!;
Trajectories
use Trajectory;
use TemporalPoint;
use Point;
use ;
// Create a movement trajectory
let start_time = now;
let points = vec!;
let trajectory = new;
println!;
3D Bounding Boxes
use BoundingBox3D;
use Point3d;
// Create a 3D airspace boundary
let airspace = new;
// Check if a drone is within airspace
let drone = new;
assert!;
Serialization
All types support Serde serialization:
use TemporalPoint;
use Point;
use SystemTime;
let point = new;
// Serialize to JSON
let json = to_string.unwrap;
// Deserialize from JSON
let deserialized: TemporalPoint = from_str.unwrap;
GeoJSON Support
Enable the geojson feature for GeoJSON format support:
use Point3d;
use Point;
// With the geojson feature enabled, you can work with GeoJSON data
// Example: Convert from GeoJSON Feature
let geojson_str = r#"{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0060, 40.7128]
}
}"#;
// Parse and use GeoJSON with spatio-types
// (Exact API depends on your conversion implementation)
Use Cases
This crate is ideal for:
- GPS tracking - Store and query vehicle, drone, or person locations over time
- Geofencing - Define and check polygon/bounding box boundaries
- Movement analysis - Track and analyze trajectories and paths
- 3D spatial data - Work with altitude-aware location data
- Time-series geospatial - Combine location and temporal information
Features
- Zero-copy operations where possible
- Serde integration for easy serialization
- Built on
geotypes for compatibility with the Rust geospatial ecosystem - Time-aware with
SystemTimetimestamps - 3D support with altitude/elevation data
- GeoJSON support (optional) - Enable with the
geojsonfeature flag
Integration with Spatio
This crate is primarily used by the Spatio database, but can be used standalone for any application needing spatio-temporal types.
use *;
use TemporalPoint;
let mut db = memory?;
// spatio-types work seamlessly with Spatio
let temporal_point = new;
Documentation
- API Documentation: docs.rs/spatio-types
- Spatio Database: github.com/pkvartsianyi/spatio
- Geo Crate: docs.rs/geo
License
MIT - see LICENSE
Contributing
Contributions are welcome! Please visit the Spatio repository for contribution guidelines.