| Crates.io | spatio-types |
| lib.rs | spatio-types |
| version | 0.2.0 |
| created_at | 2025-11-03 15:11:33.180116+00 |
| updated_at | 2026-01-11 01:55:32.307884+00 |
| description | Core spatial and temporal data types for the Spatio database |
| homepage | |
| repository | https://github.com/pkvartsianyi/spatio |
| max_upload_size | |
| id | 1914812 |
| size | 74,077 |
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.
[dependencies]
spatio-types = "0.1"
[dependencies]
# Enable GeoJSON support for serialization/deserialization
spatio-types = { version = "0.1", features = ["geojson"] }
TemporalPoint - 2D point with timestampTemporalPoint3D - 3D point with timestamp and altitudePoint3d - 3D point with altitudePolygonDynamic - 2D polygon with dynamic metadataPolygon3D - 3D polygon with altitudePolygonDynamic3D - 3D polygon with dynamic metadataTrajectory - Collection of 2D temporal points representing movementTrajectory3D - Collection of 3D temporal points with altitudeBoundingBox2D - 2D rectangular boundsBoundingBox3D - 3D cuboid boundsTemporalBoundingBox2D - 2D bounds with time rangeTemporalBoundingBox3D - 3D bounds with time rangeuse spatio_types::point::TemporalPoint;
use spatio_types::geo::Point;
use std::time::SystemTime;
// Create a temporal point (location with timestamp)
let point = Point::new(-74.0060, 40.7128); // NYC coordinates
let temporal_point = TemporalPoint::new(point, SystemTime::now());
println!("Location: {:?} at {:?}", temporal_point.point, temporal_point.timestamp);
use spatio_types::point::Point3d;
// Create a 3D point with altitude
let drone_position = Point3d::new(-74.0060, 40.7128, 100.0);
println!("Drone at altitude: {} meters", drone_position.altitude);
use spatio_types::bbox::BoundingBox2D;
use spatio_types::geo::Point;
// Create a bounding box for Manhattan
let manhattan = BoundingBox2D::new(-74.0479, 40.6829, -73.9067, 40.8820);
// Check if a point is within bounds
let empire_state = Point::new(-73.9857, 40.7484);
assert!(manhattan.contains_point(&empire_state));
// Get the center point
let center = manhattan.center();
println!("Manhattan center: {:?}", center);
use spatio_types::trajectory::Trajectory;
use spatio_types::point::TemporalPoint;
use spatio_types::geo::Point;
use std::time::{SystemTime, Duration};
// Create a movement trajectory
let start_time = SystemTime::now();
let points = vec![
TemporalPoint::new(
Point::new(-74.00, 40.71),
start_time
),
TemporalPoint::new(
Point::new(-74.01, 40.72),
start_time + Duration::from_secs(60)
),
TemporalPoint::new(
Point::new(-74.02, 40.73),
start_time + Duration::from_secs(120)
),
];
let trajectory = Trajectory::new(points);
println!("Trajectory has {} points", trajectory.points.len());
use spatio_types::bbox::BoundingBox3D;
use spatio_types::point::Point3d;
// Create a 3D airspace boundary
let airspace = BoundingBox3D::new(
-74.05, 40.68, 0.0, // min_lon, min_lat, min_altitude
-73.90, 40.88, 500.0 // max_lon, max_lat, max_altitude
);
// Check if a drone is within airspace
let drone = Point3d::new(-74.00, 40.75, 150.0);
assert!(airspace.contains_point(&drone));
All types support Serde serialization:
use spatio_types::point::TemporalPoint;
use spatio_types::geo::Point;
use std::time::SystemTime;
let point = TemporalPoint::new(Point::new(-74.0, 40.7), SystemTime::now());
// Serialize to JSON
let json = serde_json::to_string(&point).unwrap();
// Deserialize from JSON
let deserialized: TemporalPoint = serde_json::from_str(&json).unwrap();
Enable the geojson feature for GeoJSON format support:
use spatio_types::point::Point3d;
use spatio_types::geo::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)
This crate is ideal for:
geo types for compatibility with the Rust geospatial ecosystemSystemTime timestampsgeojson feature flagThis crate is primarily used by the Spatio database, but can be used standalone for any application needing spatio-temporal types.
use spatio::prelude::*;
use spatio_types::point::TemporalPoint;
let mut db = Spatio::memory()?;
// spatio-types work seamlessly with Spatio
let temporal_point = TemporalPoint::new(
Point::new(-74.0, 40.7),
SystemTime::now()
);
MIT - see LICENSE
Contributions are welcome! Please visit the Spatio repository for contribution guidelines.