20 package org.matsim.pt.transitSchedule;
22 import java.io.IOException;
23 import java.io.OutputStream;
24 import java.io.UncheckedIOException;
25 import java.util.ArrayList;
26 import java.util.List;
70 public void write(OutputStream stream)
throws UncheckedIOException {
74 }
catch (IOException e) {
75 throw new UncheckedIOException(e);
79 public void write(
final String filename)
throws UncheckedIOException {
83 }
catch (IOException e) {
84 throw new UncheckedIOException(e);
88 private void writeData() throws IOException, UncheckedIOException {
90 this.
writeDoctype(Constants.TRANSIT_SCHEDULE,
"http://www.matsim.org/files/dtd/transitSchedule_v2.dtd");
107 List<Tuple<String, String>> attributes =
new ArrayList<>(5);
110 attributes.add(
createTuple(Constants.ID, stop.getId().toString()));
111 final Coord coord = this.coordinateTransformation.
transform( stop.getCoord() );
117 if (stop.getLinkId() != null) {
118 attributes.add(
createTuple(
"linkRefId", stop.getLinkId().toString()));
120 if (stop.getName() != null) {
121 attributes.add(
createTuple(
"name", stop.getName()));
123 if (stop.getStopAreaId() != null) {
124 attributes.add(
createTuple(Constants.STOP_AREA_ID, stop.getStopAreaId().toString()));
126 attributes.add(
createTuple(
"isBlocking", stop.getIsBlockingLane()));
128 this.
writeStartTag(Constants.STOP_FACILITY, attributes,
true);
130 this.
writeStartTag(Constants.STOP_FACILITY, attributes,
false);
144 List<Tuple<String, String>> attributes =
new ArrayList<>(5);
146 if (iter.hasNext()) {
147 this.
writeStartTag(Constants.MINIMAL_TRANSFER_TIMES, attributes);
148 while (iter.hasNext()) {
151 attributes.add(
createTuple(Constants.FROM_STOP, iter.getFromStopId().toString()));
152 attributes.add(
createTuple(Constants.TO_STOP, iter.getToStopId().toString()));
153 attributes.add(
createTuple(Constants.TRANSFER_TIME, iter.getSeconds()));
156 this.
writeEndTag(Constants.MINIMAL_TRANSFER_TIMES);
161 List<Tuple<String, String>> attributes =
new ArrayList<>(1);
162 attributes.add(
createTuple(Constants.ID, line.getId().toString()));
163 if (line.getName() != null) {
164 attributes.add(
createTuple(Constants.NAME, line.getName()));
180 List<Tuple<String, String>> attributes =
new ArrayList<>(1);
181 attributes.add(
createTuple(Constants.ID, route.getId().toString()));
189 if (route.getDescription() != null) {
206 private void writeRouteProfile(
final List<TransitRouteStop> stops)
throws UncheckedIOException {
210 List<Tuple<String, String>> attributes =
new ArrayList<>(4);
213 attributes.add(
createTuple(Constants.REF_ID, stop.getStopFacility().getId().toString()));
214 stop.getArrivalOffset()
215 .ifDefined(offset -> attributes.add(
createTimeTuple(Constants.ARRIVAL_OFFSET, offset)));
216 stop.getDepartureOffset().ifDefined(offset->
219 if (!stop.isAllowBoarding()) {
220 attributes.add(
createTuple(Constants.ALLOW_BOARDING, String.valueOf(stop.isAllowBoarding())));
222 if (!stop.isAllowAlighting()) {
223 attributes.add(
createTuple(Constants.ALLOW_ALIGHTING, String.valueOf(stop.isAllowAlighting())));
225 attributes.add(
createTuple(Constants.AWAIT_DEPARTURE, String.valueOf(stop.isAwaitDepartureTime())));
237 List<Tuple<String, String>> attributes =
new ArrayList<>(1);
238 attributes.add(
createTuple(Constants.REF_ID, route.getStartLinkId().toString()));
241 for (
Id<Link> linkId : route.getLinkIds()) {
243 attributes.add(
createTuple(Constants.REF_ID, linkId.toString()));
248 attributes.add(
createTuple(Constants.REF_ID, route.getEndLinkId().toString()));
259 List<Tuple<String, String>> attributes =
new ArrayList<>(3);
261 for (
Departure dep : departures.values()) {
263 attributes.add(
createTuple(Constants.ID, dep.getId().toString()));
264 attributes.add(
createTimeTuple(Constants.DEPARTURE_TIME, dep.getDepartureTime()));
265 if (dep.getVehicleId() != null) {
266 attributes.add(
createTuple(Constants.VEHICLE_REF_ID, dep.getVehicleId().toString()));
void writeRoute(final NetworkRoute route)
Attributes getAttributes()
void writeRouteProfile(final List< TransitRouteStop > stops)
final void writeXmlHead()
void writeTransitRoute(final TransitRoute route)
Map< Id< TransitStopFacility >, TransitStopFacility > getFacilities()
final AttributesXmlWriterDelegate attributesWriter
final CoordinateTransformation coordinateTransformation
void writeDepartures(final Map< Id< Departure >, Departure > departures)
void write(OutputStream stream)
final TransitSchedule schedule
static Tuple< String, String > createTimeTuple(String one, double sec)
void write(final String filename)
TransitScheduleWriterV2(final TransitSchedule schedule)
void writeMinimalTransferTimes()
final void openOutputStream(OutputStream outputStream)
final void writeContent(String content, boolean allowWhitespaces)
final void writeAttributes(final String indentation, final BufferedWriter writer, final Attributes attributes)
static boolean isEmpty(Attributes attributes)
final void openFile(final String filename)
void writeTransitLine(final TransitLine line)
TransitScheduleWriterV2(final CoordinateTransformation coordinateTransformation, final TransitSchedule schedule)
final void writeStartTag(String tagname, List< Tuple< String, String >> attributes)
MinimalTransferTimesIterator iterator()
static Tuple< String, String > createTuple(String one, String two)
final void writeEndTag(String tagname)
Map< Id< TransitLine >, TransitLine > getTransitLines()
MinimalTransferTimes getMinimalTransferTimes()
final void writeDoctype(String rootTag, String dtdUrl)