/** * Writes the transit schedule to the specified file in the file * format specified by <tt>transitSchedule_v2.dtd</tt> * * @param filename * @throws UncheckedIOException */ public void writeFileV2(final String filename) throws UncheckedIOException { log.info( Gbl.aboutToWrite( "transit schedule" , filename ) ) ; new TransitScheduleWriterV2(this.transformation, this.schedule).write(filename); } }
private void writeData() throws IOException, UncheckedIOException { this.writeXmlHead(); this.writeDoctype(Constants.TRANSIT_SCHEDULE, "http://www.matsim.org/files/dtd/transitSchedule_v2.dtd"); this.writeStartTag(Constants.TRANSIT_SCHEDULE, null); this.writer.write(NL); this.attributesWriter.writeAttributes( "\t" , this.writer , this.schedule.getAttributes() ); this.writeTransitStops(); this.writeMinimalTransferTimes(); for (TransitLine line : this.schedule.getTransitLines().values()) { writeTransitLine(line); } this.writeEndTag(Constants.TRANSIT_SCHEDULE); this.close(); }
private void writeRoute(final NetworkRoute route) throws UncheckedIOException { if (route != null) { this.writeStartTag(Constants.ROUTE, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.REF_ID, route.getStartLinkId().toString())); this.writeStartTag(Constants.LINK, attributes, true); for (Id<Link> linkId : route.getLinkIds()) { attributes.clear(); attributes.add(createTuple(Constants.REF_ID, linkId.toString())); this.writeStartTag(Constants.LINK, attributes, true); } attributes.clear(); attributes.add(createTuple(Constants.REF_ID, route.getEndLinkId().toString())); this.writeStartTag(Constants.LINK, attributes, true); this.writeEndTag(Constants.ROUTE); } }
public void write(OutputStream stream) throws UncheckedIOException { this.openOutputStream(stream); try { writeData(); } catch (IOException e) { throw new UncheckedIOException(e); } }
private void writeTransitRoute(final TransitRoute route) throws IOException, UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.ID, route.getId().toString())); this.writeStartTag(Constants.TRANSIT_ROUTE, attributes); if (!AttributesUtils.isEmpty(route.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t\t", this.writer, route.getAttributes()); } if (route.getDescription() != null) { this.writeStartTag(Constants.DESCRIPTION, null); this.writeContent(route.getDescription(), false); this.writeEndTag(Constants.DESCRIPTION); } this.writeStartTag(Constants.TRANSPORT_MODE, null); this.writeContent(route.getTransportMode(), false); this.writeEndTag(Constants.TRANSPORT_MODE); this.writeRouteProfile(route.getStops()); this.writeRoute(route.getRoute()); this.writeDepartures(route.getDepartures()); this.writeEndTag(Constants.TRANSIT_ROUTE); }
private void writeRouteProfile(final List<TransitRouteStop> stops) throws UncheckedIOException { this.writeStartTag(Constants.ROUTE_PROFILE, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<>(4); for (TransitRouteStop stop : stops) { attributes.clear(); attributes.add(createTuple(Constants.REF_ID, stop.getStopFacility().getId().toString())); if (stop.getArrivalOffset() != Time.UNDEFINED_TIME) { attributes.add(createTimeTuple(Constants.ARRIVAL_OFFSET, stop.getArrivalOffset())); } if (stop.getDepartureOffset() != Time.UNDEFINED_TIME) { attributes.add(createTimeTuple(Constants.DEPARTURE_OFFSET, stop.getDepartureOffset())); } attributes.add(createTuple(Constants.AWAIT_DEPARTURE, String.valueOf(stop.isAwaitDepartureTime()))); this.writeStartTag(Constants.STOP, attributes, true); } this.writeEndTag(Constants.ROUTE_PROFILE); }
private void writeTransitLine(final TransitLine line) throws IOException, UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); if (!AttributesUtils.isEmpty(line.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t", this.writer, line.getAttributes()); } for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
private void writeDepartures(final Map<Id<Departure>, Departure> departures) throws IOException, UncheckedIOException { this.writeStartTag(Constants.DEPARTURES, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<>(3); for (Departure dep : departures.values()) { attributes.clear(); attributes.add(createTuple(Constants.ID, dep.getId().toString())); attributes.add(createTimeTuple(Constants.DEPARTURE_TIME, dep.getDepartureTime())); if (dep.getVehicleId() != null) { attributes.add(createTuple(Constants.VEHICLE_REF_ID, dep.getVehicleId().toString())); } if (AttributesUtils.isEmpty(dep.getAttributes())) { this.writeStartTag(Constants.DEPARTURE, attributes, true); } else { this.writeStartTag(Constants.DEPARTURE, attributes, false); this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t\t\t\t", this.writer, dep.getAttributes()); this.writeEndTag(Constants.DEPARTURE); } } this.writeEndTag(Constants.DEPARTURES); } }
new TransitScheduleWriterV2(schedule).write(outputStream);
private void writeMinimalTransferTimes() { List<Tuple<String, String>> attributes = new ArrayList<>(5); MinimalTransferTimes.MinimalTransferTimesIterator iter = this.schedule.getMinimalTransferTimes().iterator(); if (iter.hasNext()) { this.writeStartTag(Constants.MINIMAL_TRANSFER_TIMES, attributes); while (iter.hasNext()) { iter.next(); attributes.clear(); attributes.add(createTuple(Constants.FROM_STOP, iter.getFromStopId().toString())); attributes.add(createTuple(Constants.TO_STOP, iter.getToStopId().toString())); attributes.add(createTuple(Constants.TRANSFER_TIME, iter.getSeconds())); this.writeStartTag(Constants.RELATION, attributes, true); } this.writeEndTag(Constants.MINIMAL_TRANSFER_TIMES); } }
private void writeTransitStops() throws IOException, UncheckedIOException { this.writeStartTag(Constants.TRANSIT_STOPS, null); attributes.add(createTuple(Constants.ID, stop.getId().toString())); final Coord coord = this.coordinateTransformation.transform( stop.getCoord() ); attributes.add(createTuple("x", coord.getX())); attributes.add(createTuple("y", coord.getY())); if (coord.hasZ()) { attributes.add(createTuple("z", coord.getZ())); attributes.add(createTuple("linkRefId", stop.getLinkId().toString())); attributes.add(createTuple("name", stop.getName())); attributes.add(createTuple(Constants.STOP_AREA_ID, stop.getStopAreaId().toString())); attributes.add(createTuple("isBlocking", stop.getIsBlockingLane())); if (AttributesUtils.isEmpty(stop.getAttributes())) { this.writeStartTag(Constants.STOP_FACILITY, attributes, true); } else { this.writeStartTag(Constants.STOP_FACILITY, attributes, false); if (!AttributesUtils.isEmpty(stop.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t\t", this.writer, stop.getAttributes()); this.writeEndTag(Constants.STOP_FACILITY); this.writeEndTag(Constants.TRANSIT_STOPS);