Skip to content
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

Support for merging multiple public transport schedules (with pt2matsim)? #50

Closed
ait-energy opened this issue Dec 14, 2018 · 2 comments
Closed

Comments

@ait-energy
Copy link

I need to merge several GTFS feeds because we want to use GTFS data sets from neighboring regions in a single simulation.

After having a look at the pt2matsim process I think the best place to do this is in an additional step before invoking PTMapper, which handles merging the unmapped transitSchedule.xml (and the vehicleDefinitions.xml). A simplistic approach would be to merge the relevant files (e.g. via xslt). A more sophisticated approach could handle duplicate ids (e.g. vehicleDefinitions>vehicle>id can easily be the same in multiple files).

I wanted to ask if someone already did this before / if there already is an established way to achieve this?

@polettif
Copy link

I don't know about an established way but there's ScheduleTools.mergeSchedules which, together with ScheduleTools.createVehicles(), could be used to achieve this. Doing this before running PTMapper is the way to go. Combining xml files should work as well I think.

@ait-energy
Copy link
Author

Great, thanks for the hint! ScheduleTools does the job well:

static final String COORDINATE_SYTEM = "epsg:XXXXX";
static final List<String> GTFS_DIRS = Arrays.asList("a", "b", "c");
static final String TRANSIT_SCHEDULE_NOT_YET_MAPPED_TO_ROADS = "transit_schedule_not_yet_mapped_to_roads.xml";
static final String TRANSIT_VEHICLES = "transit_vehicles.xml";

public static void prepareTransitSchedules() {
	TransitSchedule transitSchedule = prepareTransitSchedule(GTFS_DIRS.get(0));
	for(String gtfsDir : GTFS_DIRS.subList(1, GTFS_DIRS.size())) {
		TransitSchedule additionalSchedule = prepareTransitSchedule(gtfsDir);
		ScheduleTools.mergeSchedules(transitSchedule, additionalSchedule);
	}
	
	Vehicles transitVehicles = VehicleUtils.createVehiclesContainer();
	ScheduleTools.createVehicles(transitSchedule, transitVehicles);
	
	ScheduleTools.writeTransitSchedule(transitSchedule, TRANSIT_SCHEDULE_NOT_YET_MAPPED_TO_ROADS);
	ScheduleTools.writeVehicles(transitVehicles, TRANSIT_VEHICLES);
}

private static TransitSchedule prepareTransitSchedule(String gtfsDir) {
	String param = GtfsConverter.DAY_WITH_MOST_TRIPS;
	GtfsFeed gtfsFeed = new GtfsFeedImpl(gtfsDir);
	GtfsConverter converter = new GtfsConverter(gtfsFeed);
	converter.convert(param, COORDINATE_SYTEM);
	return converter.getSchedule();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant