/** * Writes the transit schedule to the specified file in the file * format specified by <tt>transitSchedule_v1.dtd</tt> * * @param filename * @throws UncheckedIOException */ public void writeFileV1(final String filename) throws UncheckedIOException { log.info( Gbl.aboutToWrite("transit schedule", filename) ) ; new TransitScheduleWriterV1(this.transformation, this.schedule).write(filename); }
public void write(final String filename) throws UncheckedIOException { this.openFile(filename); this.writeXmlHead(); this.writeDoctype(Constants.TRANSIT_SCHEDULE, "http://www.matsim.org/files/dtd/transitSchedule_v1.dtd"); this.writeStartTag(Constants.TRANSIT_SCHEDULE, null); this.writeTransitStops(); for (TransitLine line : this.schedule.getTransitLines().values()) { writeTransitLine(line); } this.writeEndTag(Constants.TRANSIT_SCHEDULE); this.close(); }
private void writeDepartures(final Map<Id<Departure>, Departure> departures) throws UncheckedIOException { this.writeStartTag(Constants.DEPARTURES, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(3); for (Departure dep : departures.values()) { attributes.clear(); attributes.add(this.createTuple(Constants.ID, dep.getId().toString())); attributes.add(this.createTimeTuple(Constants.DEPARTURE_TIME, dep.getDepartureTime())); if (dep.getVehicleId() != null) { attributes.add(this.createTuple(Constants.VEHICLE_REF_ID, dep.getVehicleId().toString())); } this.writeStartTag(Constants.DEPARTURE, attributes, true); } this.writeEndTag(Constants.DEPARTURES); } }
private void writeTransitRoute(final TransitRoute route) throws UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.ID, route.getId().toString())); this.writeStartTag(Constants.TRANSIT_ROUTE, attributes); 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 writeTransitLine(final TransitLine line) throws UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(this.createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
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<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.REF_ID, route.getStartLinkId().toString())); this.writeStartTag(Constants.LINK, attributes, true); for (Id<Link> linkId : route.getLinkIds()) { attributes.clear(); attributes.add(this.createTuple(Constants.REF_ID, linkId.toString())); this.writeStartTag(Constants.LINK, attributes, true); } attributes.clear(); attributes.add(this.createTuple(Constants.REF_ID, route.getEndLinkId().toString())); this.writeStartTag(Constants.LINK, attributes, true); this.writeEndTag(Constants.ROUTE); } }
private void writeTransitStops() throws UncheckedIOException { this.writeStartTag(Constants.TRANSIT_STOPS, null); List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(5); for (TransitStopFacility stop : this.schedule.getFacilities().values()) { attributes.clear(); attributes.add(this.createTuple(Constants.ID, stop.getId().toString())); final Coord coord = coordinateTransformation.transform( stop.getCoord() ); attributes.add(this.createTuple("x", coord.getX())); attributes.add(this.createTuple("y", coord.getY())); if (stop.getLinkId() != null) { attributes.add(this.createTuple("linkRefId", stop.getLinkId().toString())); } if (stop.getName() != null) { attributes.add(this.createTuple("name", stop.getName())); } attributes.add(this.createTuple("isBlocking", stop.getIsBlockingLane())); this.writeStartTag(Constants.STOP_FACILITY, attributes, true); } this.writeEndTag(Constants.TRANSIT_STOPS); }
@Test public void testOutput() { URL transitSchedule = IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("pt-tutorial"), "transitschedule.xml"); final Scenario originalScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new TransitScheduleReader(originalScenario).readURL(transitSchedule ); final String file = utils.getOutputDirectory()+"/schedule.xml"; new TransitScheduleWriterV1( transformation , originalScenario.getTransitSchedule() ).write( file ); final Scenario reprojectedScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new TransitScheduleReader(reprojectedScenario).readFile(file); assertCorrectlyReprojected( originalScenario.getTransitSchedule() , reprojectedScenario.getTransitSchedule() ); }
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<Tuple<String, String>>(4); for (TransitRouteStop stop : stops) { attributes.clear(); attributes.add(this.createTuple(Constants.REF_ID, stop.getStopFacility().getId().toString())); if (stop.getArrivalOffset() != Time.UNDEFINED_TIME) { attributes.add(this.createTimeTuple(Constants.ARRIVAL_OFFSET, stop.getArrivalOffset())); } if (stop.getDepartureOffset() != Time.UNDEFINED_TIME) { attributes.add(this.createTimeTuple(Constants.DEPARTURE_OFFSET, stop.getDepartureOffset())); } attributes.add(this.createTuple(Constants.AWAIT_DEPARTURE, String.valueOf(stop.isAwaitDepartureTime()))); this.writeStartTag(Constants.STOP, attributes, true); } this.writeEndTag(Constants.ROUTE_PROFILE); }
new TransitScheduleWriterV1(schedule1).write(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleWriterV1(schedule1).write(filename); TransitScheduleFactory builder3 = new TransitScheduleFactoryImpl(); TransitSchedule schedule3 = builder3.createTransitSchedule();