Skip to content

Commit

Permalink
[feature] read gtfs route as line
Browse files Browse the repository at this point in the history
  • Loading branch information
patochectp committed Jan 5, 2021
1 parent 5efe103 commit d606729
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 79 deletions.
5 changes: 4 additions & 1 deletion documentation/gtfs_to_ntfs_specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ In addition, the NTFS format introduces 2 objects to enable the manipulation of
Two parameters can be specified in the configuration of the converter in order to determine if on demand transport (ODT) data should be considered when reading the input GTFS (in particular, when [reading the stop_times.txt file](#reading-stop_timestxt)):

* a boolean parameter `odt`, by default set to `false`, indicating if the GTFS should be considered as containing ODT information
* a string `odt_comment` setting the message associated to an ODT comment.
* a string `odt_comment` setting the message associated to an ODT comment.

A third boolean parameter (`read-as-line`) may affect the reading of the file [routes.txt](#reading-routestxt). If true, each GTFS "Route" will generate a different "Line" else we group the routes by "agency_id" and "route_short_name" (or "route_long_name" if the short name is empty) and create a "Line" for each group.


## Mapping of objects between GTFS and NTFS

Expand Down
16 changes: 2 additions & 14 deletions examples/gtfs_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>

use serde_json::json;
use std::collections::BTreeMap;
use transit_model::{
gtfs,
objects::{Contributor, Dataset},
Result,
};
use transit_model::{gtfs, Result};

fn run() -> Result<()> {
let configuration: gtfs::Configuration = gtfs::Configuration {
contributor: Contributor::default(),
dataset: Dataset::default(),
feed_infos: BTreeMap::new(),
prefix_conf: None,
on_demand_transport: false,
on_demand_transport_comment: None,
};
let configuration = gtfs::Configuration::default();
// read GTFS from current directory
let objects = gtfs::read_from_path(".", configuration)?;
// output internal model as JSON
Expand Down
2 changes: 1 addition & 1 deletion gtfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gtfs2netexfr"
version = "1.0.0"
version = "1.1.0"
authors = ["Kisio Digital <[email protected]>"]
license = "AGPL-3.0-only"
description = "Binary to convert Transit data from GTFS format to NeTEx France"
Expand Down
2 changes: 1 addition & 1 deletion gtfs2netexfr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ fn run(opt: Opt) -> Result<()> {
contributor,
dataset,
feed_infos,
prefix_conf: None,
on_demand_transport: opt.odt,
on_demand_transport_comment: opt.odt_comment,
..Default::default()
};

let model = if opt.input.is_file() {
Expand Down
2 changes: 1 addition & 1 deletion gtfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gtfs2ntfs"
version = "1.0.1"
version = "1.1.0"
authors = ["Kisio Digital <[email protected]>"]
license = "AGPL-3.0-only"
description = "Binary to convert Transit data from GTFS format to NTFS"
Expand Down
7 changes: 7 additions & 0 deletions gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ struct Opt {
#[structopt(long = "odt-comment")]
odt_comment: Option<String>,

/// If true, each GTFS `Route` will generate a different `Line`.
/// Else we group the routes by `agency_id` and `route_short_name`
/// (or `route_long_name` if the short name is empty) and create a `Line` for each group.
#[structopt(long = "read-as-line")]
read_as_line: bool,

/// Current datetime.
#[structopt(
short = "x",
Expand Down Expand Up @@ -118,6 +124,7 @@ fn run(opt: Opt) -> Result<()> {
prefix_conf: Some(prefix_conf),
on_demand_transport: opt.odt,
on_demand_transport_comment: opt.odt_comment,
read_as_line: opt.read_as_line,
};

let model = if opt.input.is_file() {
Expand Down
8 changes: 7 additions & 1 deletion src/gtfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ struct Shape {
}

///parameters consolidation
#[derive(Default)]
pub struct Configuration {
/// The Contributor providing the Dataset
pub contributor: Contributor,
Expand All @@ -266,6 +267,10 @@ pub struct Configuration {
pub on_demand_transport: bool,
/// on demand transport comment template
pub on_demand_transport_comment: Option<String>,
/// If true, each GTFS `Route` will generate a different `Line`.
/// Else we group the routes by `agency_id` and `route_short_name`
/// (or `route_long_name` if the short name is empty) and create a `Line` for each group.
pub read_as_line: bool,
}

fn read<H>(file_handler: &mut H, configuration: Configuration) -> Result<Model>
Expand All @@ -282,6 +287,7 @@ where
prefix_conf,
on_demand_transport,
on_demand_transport_comment,
read_as_line,
} = configuration;

manage_calendars(file_handler, &mut collections)?;
Expand All @@ -303,7 +309,7 @@ where

read::manage_shapes(&mut collections, file_handler)?;

read::read_routes(file_handler, &mut collections)?;
read::read_routes(file_handler, &mut collections, read_as_line)?;
collections.equipments = CollectionWithId::new(equipments.into_equipments())?;
read::manage_stop_times(
&mut collections,
Expand Down
Loading

0 comments on commit d606729

Please sign in to comment.