forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetexModule.java
130 lines (106 loc) · 4.91 KB
/
NetexModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.opentripplanner.netex;
import org.opentripplanner.ext.flex.FlexTripsMapper;
import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.AddTransitModelEntitiesToGraph;
import org.opentripplanner.graph_builder.module.GtfsFeedId;
import org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.model.OtpTransitService;
import org.opentripplanner.model.calendar.CalendarServiceData;
import org.opentripplanner.model.calendar.ServiceDateInterval;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.fares.impl.DefaultFareServiceFactory;
import org.opentripplanner.routing.fares.FareServiceFactory;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.util.OTPFeature;
import java.util.HashMap;
import java.util.List;
/**
* This module is used for importing the NeTEx CEN Technical Standard for exchanging
* Public Transport schedules and related data
* (<a href="http://netex-cen.eu/">http://netex-cen.eu/</a>). Currently it only supports the
* Norwegian profile
* (<a href="https://enturas.atlassian.net/wiki/spaces/PUBLIC/">https://enturas.atlassian.net/wiki/spaces/PUBLIC/</a>),
* but it is intended to be updated later to support other profiles.
*/
public class NetexModule implements GraphBuilderModule {
private final double maxStopToShapeSnapDistance;
private final int subwayAccessTime;
private final int maxInterlineDistance;
private final String netexFeedId;
/**
* @see BuildConfig#transitServiceStart
* @see BuildConfig#transitServiceEnd
*/
private final ServiceDateInterval transitPeriodLimit;
private final List<NetexBundle> netexBundles;
private final FareServiceFactory fareServiceFactory = new DefaultFareServiceFactory();
public NetexModule(
String netexFeedId,
int subwayAccessTime,
int maxInterlineDistance,
double maxStopToShapeSnapDistance,
ServiceDateInterval transitPeriodLimit,
List<NetexBundle> netexBundles
) {
this.netexFeedId = netexFeedId;
this.subwayAccessTime = subwayAccessTime;
this.maxInterlineDistance = maxInterlineDistance;
this.transitPeriodLimit = transitPeriodLimit;
this.netexBundles = netexBundles;
this.maxStopToShapeSnapDistance = maxStopToShapeSnapDistance;
}
@Override
public void buildGraph(
Graph graph,
HashMap<Class<?>, Object> extra,
DataImportIssueStore issueStore
) {
graph.clearTimeZone();
CalendarServiceData calendarServiceData = graph.getCalendarDataService();
try {
for (NetexBundle netexBundle : netexBundles) {
netexBundle.checkInputs();
OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(
graph.deduplicator,
issueStore
);
transitBuilder.limitServiceDays(transitPeriodLimit);
calendarServiceData.add(transitBuilder.buildCalendarServiceData());
if (OTPFeature.FlexRouting.isOn()) {
transitBuilder.getFlexTripsById().addAll(
FlexTripsMapper.createFlexTrips(transitBuilder, issueStore)
);
}
OtpTransitService otpService = transitBuilder.build();
// TODO OTP2 - Move this into the AddTransitModelEntitiesToGraph
// - and make sure thay also work with GTFS feeds - GTFS do no
// - have operators and notice assignments.
graph.getOperators().addAll(otpService.getAllOperators());
graph.addNoticeAssignments(otpService.getNoticeAssignments());
GtfsFeedId feedId = new GtfsFeedId.Builder().id(netexFeedId).build();
AddTransitModelEntitiesToGraph.addToGraph(
feedId, otpService, subwayAccessTime, graph
);
new GeometryAndBlockProcessor(
otpService,
fareServiceFactory,
maxStopToShapeSnapDistance,
maxInterlineDistance
).run(graph, issueStore);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
graph.clearCachedCalenderService();
graph.putService(CalendarServiceData.class, calendarServiceData);
graph.updateTransitFeedValidity(calendarServiceData, issueStore);
graph.hasTransit = true;
graph.calculateTransitCenter();
}
@Override
public void checkInputs() {
netexBundles.forEach(NetexBundle::checkInputs);
}
}