diff --git a/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java b/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java index d5c1cea..02a9c5a 100644 --- a/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java +++ b/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java @@ -1,5 +1,6 @@ package org.matsim.contrib.gtfs; +import java.text.Normalizer; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -92,6 +93,10 @@ public void convert(){ activeTrips.stream().map(trip -> feed.routes.get(trip.route_id)).distinct().forEach(route -> { TransitLine tl = ts.getFactory().createTransitLine(getReadableTransitLineId(route)); ts.addTransitLine(tl); + tl.getAttributes().putAttribute("gtfs_agency_id", String.valueOf(route.agency_id)); + tl.getAttributes().putAttribute("gtfs_route_type", String.valueOf(route.route_type)); + tl.getAttributes().putAttribute("gtfs_route_short_name", + Normalizer.normalize(route.route_short_name, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "")); // replaces non ascii symbols }); this.convertTrips(activeTrips); @@ -218,7 +223,11 @@ private Id getReadableTransitLineId(Trip trip) { } private Id getReadableTransitLineId(Route route) { - return Id.create(route.route_short_name == null ? "XXX---" + route.route_id : route.route_short_name + "---" + route.route_id, TransitLine.class); + String asciiShortName = "XXX"; + if (route.route_short_name != null && route.route_short_name.length() > 0) { + asciiShortName = Normalizer.normalize(route.route_short_name, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); + } + return Id.create(asciiShortName + "---" + route.route_id, TransitLine.class); } } diff --git a/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java b/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java index e104d3a..7334766 100644 --- a/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java +++ b/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java @@ -14,6 +14,7 @@ import org.matsim.pt.transitSchedule.api.TransitRouteStop; import org.matsim.pt.transitSchedule.api.TransitSchedule; import org.matsim.pt.transitSchedule.api.TransitScheduleReader; +import org.matsim.pt.transitSchedule.api.TransitStopFacility; import java.time.LocalDate; @@ -44,15 +45,19 @@ private void compareTransitSchedules(MutableScenario sc1, MutableScenario sc2) { TransitSchedule ts1 = sc1.getTransitSchedule(); TransitSchedule ts2 = sc2.getTransitSchedule(); Assert.assertEquals(ts1.getFacilities().size(), ts2.getFacilities().size()); - for(Id stopId: ts1.getFacilities().keySet()){ + for(Id stopId: ts1.getFacilities().keySet()){ Assert.assertEquals(ts1.getFacilities().get(stopId).getName(), ts2.getFacilities().get(stopId).getName()); Assert.assertEquals(ts1.getFacilities().get(stopId).getCoord(), ts2.getFacilities().get(stopId).getCoord()); Assert.assertEquals(ts1.getFacilities().get(stopId).getLinkId(), ts2.getFacilities().get(stopId).getLinkId()); } Assert.assertEquals(ts1.getTransitLines().size(), ts2.getTransitLines().size()); - for(Id lineId: ts1.getTransitLines().keySet()){ + for(Id lineId: ts1.getTransitLines().keySet()){ Assert.assertEquals(ts1.getTransitLines().get(lineId).getRoutes().size(), ts1.getTransitLines().get(lineId).getRoutes().size()); - for(Id routeId: ts1.getTransitLines().get(lineId).getRoutes().keySet()){ + Assert.assertEquals(ts1.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_agency_id"), ts2.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_agency_id")); + Assert.assertEquals(ts1.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_route_type"), ts2.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_route_type")); + Assert.assertEquals(ts1.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_route_short_name"), ts2.getTransitLines().get(lineId).getAttributes().getAttribute("gtfs_route_short_name")); + + for(Id routeId: ts1.getTransitLines().get(lineId).getRoutes().keySet()){ TransitRoute tr1 = ts1.getTransitLines().get(lineId).getRoutes().get(routeId); TransitRoute tr2 = ts2.getTransitLines().get(lineId).getRoutes().get(routeId); Assert.assertEquals(tr1.getStops().size(), tr2.getStops().size()); diff --git a/test/input/transitSchedule.xml b/test/input/transitSchedule.xml index f0b2045..10284e1 100644 --- a/test/input/transitSchedule.xml +++ b/test/input/transitSchedule.xml @@ -1,5 +1,5 @@ - + @@ -7,6 +7,12 @@ + + Unitrans + Test Route + 3 + + bus @@ -42,4 +48,4 @@ - \ No newline at end of file +