-
Notifications
You must be signed in to change notification settings - Fork 2
OMF Transportation Serialization logic #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7b5af05
f52e2b3
fc35809
c08c5cf
a0e7a38
76225e4
0080a5c
ec1dcf2
b65649c
6f776a5
bee590a
53b5790
a3080f8
b77b6c1
1a4d6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| mod omf_app; | ||
|
|
||
| pub use omf_app::OmfApp; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| use std::path::Path; | ||
|
|
||
| use clap::{Parser, Subcommand}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{ | ||
| collection::{ | ||
| ObjectStoreSource, OvertureMapsCollectionError, OvertureMapsCollectorConfig, | ||
| ReleaseVersion, RowFilterConfig, TransportationCollection, | ||
| }, | ||
| graph::OmfGraphVectorized, | ||
| }; | ||
|
|
||
| /// command line tool for batch downloading and summarizing of GTFS archives | ||
| #[derive(Parser)] | ||
| #[command(author, version, about, long_about = None)] | ||
| #[command(propagate_version = true)] | ||
| pub struct OmfApp { | ||
| #[command(subcommand)] | ||
| pub op: OmfOperation, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, Subcommand)] | ||
| pub enum OmfOperation { | ||
| /// download all of the GTFS archives | ||
|
||
| Download, | ||
| } | ||
|
|
||
| impl OmfOperation { | ||
| pub fn run(self) -> Result<(), OvertureMapsCollectionError> { | ||
| match self { | ||
| OmfOperation::Download => { | ||
| let collector = | ||
| OvertureMapsCollectorConfig::new(ObjectStoreSource::AmazonS3, 128).build()?; | ||
| let release = ReleaseVersion::Latest; | ||
| let row_filter_config = RowFilterConfig::Bbox { | ||
| xmin: -105.254, | ||
| xmax: -105.197, | ||
| ymin: 39.733, | ||
| ymax: 39.784, | ||
| }; | ||
|
|
||
| let collection = TransportationCollection::try_from_collector( | ||
| collector, | ||
| release, | ||
| Some(row_filter_config), | ||
| )?; | ||
| let vectorized_graph = OmfGraphVectorized::try_from_collection(collection, 0)?; | ||
| vectorized_graph.write_compass(Path::new("./"), true)?; | ||
|
Comment on lines
+36
to
+49
|
||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||
| use serde::{Deserialize, Serialize}; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #[derive(Debug, Serialize, Deserialize)] | ||||||||||||||||||||||||||||
| struct OvertureSerializeOptions { | ||||||||||||||||||||||||||||
| out_file: String, | ||||||||||||||||||||||||||||
| scope: SerializeScope, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #[derive(Debug, Serialize, Deserialize)] | ||||||||||||||||||||||||||||
| enum SerializeScope { | ||||||||||||||||||||||||||||
| Complete, | ||||||||||||||||||||||||||||
| Compass, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+13
|
||||||||||||||||||||||||||||
| use serde::{Deserialize, Serialize}; | |
| #[derive(Debug, Serialize, Deserialize)] | |
| struct OvertureSerializeOptions { | |
| out_file: String, | |
| scope: SerializeScope, | |
| } | |
| #[derive(Debug, Serialize, Deserialize)] | |
| enum SerializeScope { | |
| Complete, | |
| Compass, | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| use bambam_omf::app::OmfApp; | ||
| use clap::Parser; | ||
|
|
||
| fn main() { | ||
| env_logger::init(); | ||
| let args = OmfApp::parse(); | ||
| args.op.run().unwrap() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| use crate::collection::{ | ||
| OvertureMapsCollectionError, OvertureMapsCollector, OvertureRecord, OvertureRecordType, | ||
| ReleaseVersion, RowFilterConfig, TransportationConnectorRecord, TransportationSegmentRecord, | ||
| }; | ||
|
|
||
| pub struct TransportationCollection { | ||
| pub connectors: Vec<TransportationConnectorRecord>, | ||
| pub segments: Vec<TransportationSegmentRecord>, | ||
| } | ||
|
|
||
| impl TransportationCollection { | ||
| /// Use a pre-built collector and download configuration to | ||
| /// retrieve connectors and segments for a specified query | ||
| pub fn try_from_collector( | ||
| collector: OvertureMapsCollector, | ||
| release: ReleaseVersion, | ||
| row_filter_config: Option<RowFilterConfig>, | ||
| ) -> Result<Self, OvertureMapsCollectionError> { | ||
| let connectors = collector | ||
| .collect_from_release( | ||
| release.clone(), | ||
| &OvertureRecordType::Connector, | ||
| row_filter_config.clone(), | ||
| )? | ||
| .into_iter() | ||
| .map(|record| match record { | ||
| OvertureRecord::Connector(transportation_connector_record) => { | ||
| Ok(transportation_connector_record) | ||
| } | ||
| _ => Err(OvertureMapsCollectionError::DeserializeTypeError(format!( | ||
| "expected connector type, got {record:?}" | ||
| ))), | ||
| }) | ||
| .collect::<Result<Vec<TransportationConnectorRecord>, OvertureMapsCollectionError>>()?; | ||
|
|
||
| let segments = collector | ||
| .collect_from_release( | ||
| release.clone(), | ||
| &OvertureRecordType::Segment, | ||
| row_filter_config.clone(), | ||
| )? | ||
| .into_iter() | ||
| .map(|record| match record { | ||
| OvertureRecord::Segment(transportation_connector_record) => { | ||
| Ok(transportation_connector_record) | ||
robfitzgerald marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| _ => Err(OvertureMapsCollectionError::DeserializeTypeError(format!( | ||
| "expected segment type, got {record:?}" | ||
| ))), | ||
| }) | ||
| .collect::<Result<Vec<TransportationSegmentRecord>, OvertureMapsCollectionError>>()?; | ||
|
|
||
| Ok(Self { | ||
| connectors, | ||
| segments, | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use geo::Geometry; | ||
| use geo::{Geometry, Haversine, Length}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::collection::{OvertureMapsCollectionError, OvertureRecord}; | ||
|
|
@@ -12,16 +12,16 @@ use super::{OvertureMapsBbox, OvertureMapsNames, OvertureMapsSource}; | |
| /// and other attributes relevant to routing and mapping. | ||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct TransportationSegmentRecord { | ||
| id: Option<String>, | ||
| pub id: String, | ||
| #[serde(deserialize_with = "deserialize_geometry")] | ||
| geometry: Option<Geometry>, | ||
| pub geometry: Option<Geometry>, | ||
| bbox: OvertureMapsBbox, | ||
| version: i32, | ||
| sources: Option<Vec<Option<OvertureMapsSource>>>, | ||
| subtype: Option<String>, | ||
| class: Option<String>, | ||
| names: Option<OvertureMapsNames>, | ||
| connectors: Option<Vec<ConnectorReference>>, | ||
| pub connectors: Option<Vec<ConnectorReference>>, | ||
| routes: Option<Vec<SegmentRoute>>, | ||
| subclass_rules: Option<Vec<SegmentValueBetween<String>>>, | ||
| access_restrictions: Option<Vec<SegmentAccessRestriction>>, | ||
|
|
@@ -49,10 +49,28 @@ impl TryFrom<OvertureRecord> for TransportationSegmentRecord { | |
| } | ||
| } | ||
|
|
||
| impl TransportationSegmentRecord { | ||
| pub fn get_distance_at(&self, at: f64) -> Result<f64, OvertureMapsCollectionError> { | ||
| let geometry = | ||
| self.geometry | ||
| .as_ref() | ||
| .ok_or(OvertureMapsCollectionError::InvalidGeometry( | ||
| "empty geometry".to_string(), | ||
| ))?; | ||
|
|
||
| match geometry { | ||
| Geometry::LineString(line_string) => Ok(Haversine.length(line_string) * at), | ||
|
||
| _ => Err(OvertureMapsCollectionError::InvalidGeometry(format!( | ||
| "geometry was not a linestring {geometry:?}" | ||
| ))), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct ConnectorReference { | ||
| connector_id: String, | ||
| at: f64, | ||
| pub struct ConnectorReference { | ||
| pub connector_id: String, | ||
| pub at: f64, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| mod omf_graph; | ||
| mod segment_split; | ||
| mod serialize_ops; | ||
| mod vertex_serializable; | ||
|
|
||
| pub use omf_graph::OmfGraphVectorized; |
Uh oh!
There was an error while loading. Please reload this page.