20 package org.matsim.pt.transitSchedule;
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
24 import java.util.List;
26 import java.util.Stack;
27 import java.util.concurrent.ConcurrentHashMap;
29 import org.apache.logging.log4j.LogManager;
30 import org.apache.logging.log4j.Logger;
53 import org.xml.sax.Attributes;
84 final String externalInputCRS,
85 final String targetCRS,
91 String externalInputCRS,
100 if (externalInputCRS != null && targetCRS != null) {
108 if (Constants.STOP_FACILITY.equals(name)) {
109 boolean isBlocking = Boolean.parseBoolean(atts.getValue(Constants.IS_BLOCKING));
110 Coord coord = atts.getValue(Constants.Z) == null ?
111 new Coord(Double.parseDouble(atts.getValue(Constants.X)), Double.parseDouble(atts.getValue(Constants.Y))) :
112 new Coord(Double.parseDouble(atts.getValue(Constants.X)), Double.parseDouble(atts.getValue(Constants.Y)), Double.parseDouble(atts.getValue(Constants.Z)));
116 this.coordinateTransformation.
transform(coord),
119 if (atts.getValue(Constants.LINK_REF_ID) != null) {
123 if (atts.getValue(Constants.NAME) != null) {
124 stop.
setName(this.cache.
get(atts.getValue(Constants.NAME)));
126 if (atts.getValue(Constants.STOP_AREA_ID) != null) {
130 }
else if (Constants.TRANSIT_LINE.equals(name)) {
134 if (atts.getValue(Constants.NAME) != null) {
135 this.currentTransitLine.
setName(atts.getValue(Constants.NAME));
138 }
else if (Constants.TRANSIT_ROUTE.equals(name)) {
142 }
else if (Constants.DEPARTURE.equals(name)) {
146 String vehicleRefId = atts.getValue(Constants.VEHICLE_REF_ID);
147 if (vehicleRefId != null) {
150 this.currentTransitRoute.
departures.put(
id, this.currentDeparture);
151 }
else if (Constants.ROUTE_PROFILE.equals(name)) {
152 this.currentRouteProfile =
new TempRoute();
153 }
else if (Constants.LINK.equals(name)) {
154 String linkStr = atts.getValue(Constants.REF_ID);
155 if (!linkStr.contains(
" ")) {
158 String[] links = linkStr.split(
" ");
159 for (
int i = 0; i < links.length; i++) {
163 }
else if (Constants.STOP.equals(name)) {
166 if (facility == null) {
167 throw new RuntimeException(
"no stop/facility with id " + atts.getValue(Constants.REF_ID));
170 String arrival = atts.getValue(Constants.ARRIVAL_OFFSET);
171 String departure = atts.getValue(Constants.DEPARTURE_OFFSET);
172 if (arrival != null) {
175 if (departure != null) {
178 stopBuilder.allowBoarding(Boolean.parseBoolean(atts.getValue(Constants.ALLOW_BOARDING)));
179 stopBuilder.allowAlighting(Boolean.parseBoolean(atts.getValue(Constants.ALLOW_ALIGHTING)));
180 stopBuilder.awaitDepartureTime(Boolean.parseBoolean(atts.getValue(Constants.AWAIT_DEPARTURE)));
181 this.currentTransitRoute.stopBuilders.add(stopBuilder);
182 }
else if (Constants.RELATION.equals(name)) {
185 double transferTime =
Time.
parseTime(atts.getValue(Constants.TRANSFER_TIME));
187 }
else if (Constants.ATTRIBUTE.equals(name)) {
189 }
else if (Constants.ATTRIBUTES.equals(name)) {
191 }
else if (Constants.TRANSIT_SCHEDULE.equals(name)) {
197 public void endTag(
final String name,
final String content,
final Stack<String> context) {
198 if (Constants.DEPARTURE.equals(name)) {
199 this.currentDeparture = null;
201 if (Constants.DESCRIPTION.equals(name) && Constants.TRANSIT_ROUTE.equals(context.peek())) {
203 }
else if (Constants.TRANSPORT_MODE.equals(name)) {
204 this.currentTransitRoute.mode = content.intern();
205 }
else if (Constants.DEPARTURE.equals(name)) {
206 this.currentDeparture = null;
207 }
else if (Constants.TRANSIT_ROUTE.equals(name)) {
208 List<TransitRouteStop> stops =
new ArrayList<>(this.currentTransitRoute.stopBuilders.size());
209 this.currentTransitRoute.stopBuilders.forEach(stopBuilder -> stops.add(stopBuilder.build()));
211 if (this.currentRouteProfile.firstLinkId != null) {
212 if (this.currentRouteProfile.lastLinkId == null) {
213 this.currentRouteProfile.lastLinkId = this.currentRouteProfile.firstLinkId;
215 route = this.routeFactory.createRoute(
NetworkRoute.class,
this.currentRouteProfile.firstLinkId,
this.currentRouteProfile.lastLinkId);
216 route.
setLinkIds(this.currentRouteProfile.firstLinkId,
this.currentRouteProfile.linkIds,
this.currentRouteProfile.lastLinkId);
224 this.currentTransitLine.
addRoute(transitRoute);
225 this.currentTransitRoute = null;
226 }
else if (Constants.TRANSIT_LINE.equals(name)) {
227 this.currentTransitLine = null;
228 }
else if (Constants.ATTRIBUTE.equals(name)) {
229 this.attributesDelegate.
endTag(name, content, context);
230 }
else if (Constants.ATTRIBUTES.equals(name)) {
231 if (context.peek().equals(Constants.TRANSIT_SCHEDULE)) {
234 if (inputCRS != null && targetCRS != null) {
235 if (externalInputCRS != null) {
237 log.warn(
"coordinate transformation defined both in config and in input file: setting from input file will be used");
261 List<Id<Link>> linkIds =
new ArrayList<>();
270 if (this.firstLinkId == null) {
271 this.firstLinkId = linkId;
272 }
else if (this.lastLinkId == null) {
273 this.lastLinkId = linkId;
275 this.linkIds.add(this.lastLinkId);
276 this.lastLinkId = linkId;
284 private ConcurrentHashMap<String, String> cache =
new ConcurrentHashMap<>(10000);
293 public String
get(
final String string) {
294 if (
string == null) {
297 String s = this.cache.putIfAbsent(
string,
string);
Attributes getAttributes()
void ifDefined(DoubleConsumer action)
Map< Id< TransitStopFacility >, TransitStopFacility > getFacilities()
void addLink(final Id< Link > linkId)
void setStopAreaId(Id< TransitStopArea > stopAreaId)
void addTransitLine(final TransitLine line)
TransitScheduleReaderV2(String externalInputCRS, String targetCRS, TransitSchedule schedule, RouteFactories routeFactory)
TransitScheduleFactory getFactory()
final RouteFactories routeFactory
TransitScheduleReaderV2(final TransitSchedule schedule, final RouteFactories routeFactory)
static< T extends MatsimToplevelContainer &Attributable > void putCRS(T container, String CRS)
static void copyTo(Attributes from, Attributes to)
Map< Id< Departure >, Departure > departures
void addRoute(final TransitRoute transitRoute)
static final String INPUT_CRS_ATT
void setDescription(final String description)
void startTag(final String name, final Attributes atts, final Stack< String > context)
final String externalInputCRS
static< T > Id< T > create(final long key, final Class< T > type)
static final OptionalTime parseOptionalTime(final String time)
void endTag(final String name, final String content, final Stack< String > context)
static final double parseTime(final String time)
void setVehicleId(final Id< Vehicle > vehicleId)
RouteFactories getRouteFactories()
Object getAttribute(final String attribute)
Population getPopulation()
void addDeparture(final Departure departure)
String get(final String string)
Object putAttribute(final String attribute, final Object value)
abstract TransitLine createTransitLine(final Id< TransitLine > lineId)
TransitScheduleReaderV2(final String externalInputCRS, final String targetCRS, final Scenario scenario)
void setName(final String name)
final org.matsim.utils.objectattributes.attributable.Attributes attributes
TempTransitRoute(final Id< TransitRoute > id)
double set(Id< TransitStopFacility > fromStop, Id< TransitStopFacility > toStop, double seconds)
abstract TransitStopFacility createTransitStopFacility(final Id< TransitStopFacility > facilityId, final Coord coordinate, final boolean blocksLane)
void endTag(String name, String content, Stack< String > context)
final AttributesXmlReaderDelegate attributesDelegate
TransitLine currentTransitLine
void setName(final String name)
void addStopFacility(final TransitStopFacility stop)
PopulationFactory getFactory()
final TransitSchedule schedule
TransitSchedule getTransitSchedule()
abstract TransitRoute createTransitRoute(final Id< TransitRoute > routeId, final NetworkRoute route, final List< TransitRouteStop > stops, final String mode)
void setLinkIds(final Id< Link > startLinkId, final List< Id< Link >> linkIds, final Id< Link > endLinkId)
org.matsim.utils.objectattributes.attributable.Attributes currentAttributes
void setLinkId(final Id< Link > linkId)
MinimalTransferTimes getMinimalTransferTimes()
TempTransitRoute currentTransitRoute
final Id< TransitRoute > id
Departure currentDeparture
TempRoute currentRouteProfile
CoordinateTransformation coordinateTransformation
void startTag(String name, org.xml.sax.Attributes atts, Stack< String > context, Attributes currentAttributes)