diff --git a/pom.xml b/pom.xml
index 38dbf83..a89fec4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,14 +3,19 @@
4.0.0
org.matsim.contrib
matsim-gtfs
- 11.1-SNAPSHOT
+ 12.1-SNAPSHOT
-
osgeo
- Geotools repository
- http://download.osgeo.org/webdav/geotools
+ OSGeo Release Repository
+ https://repo.osgeo.org/repository/release/
+
+ false
+
+
+ true
+
matsim
@@ -47,7 +52,7 @@
org.matsim
matsim
- 11.0
+ 12.0
com.conveyal
diff --git a/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java b/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java
index 7b946ae..34567dc 100644
--- a/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java
+++ b/src/main/java/org/matsim/contrib/gtfs/GtfsConverter.java
@@ -157,19 +157,17 @@ private void convertTrips(List trips) {
for(StopTime stopTime : feed.getInterpolatedStopTimesForTrip(trip.trip_id)) {
Id stopId = Id.create(stopTime.stop_id, TransitStopFacility.class);
TransitStopFacility stop = ts.getFacilities().get(stopId);
- double arrivalOffset;
+
+ TransitRouteStop.Builder builder = ts.getFactory().createTransitRouteStopBuilder(stop);
if (stopTime.arrival_time != Integer.MIN_VALUE) {
- arrivalOffset = Time.parseTime(String.valueOf(stopTime.arrival_time)) - departureTime;
- } else {
- arrivalOffset = Time.UNDEFINED_TIME;
+ double arrivalOffset = Time.parseTime(String.valueOf(stopTime.arrival_time)) - departureTime;
+ builder.arrivalOffset(arrivalOffset);
}
- double departureOffset;
if (stopTime.departure_time != Integer.MIN_VALUE) {
- departureOffset = Time.parseTime(String.valueOf(stopTime.departure_time)) - departureTime;
- } else {
- departureOffset = Time.UNDEFINED_TIME;
+ double departureOffset = Time.parseTime(String.valueOf(stopTime.departure_time)) - departureTime;
+ builder.departureOffset(departureOffset);
}
- TransitRouteStop routeStop = ts.getFactory().createTransitRouteStop(stop, arrivalOffset, departureOffset);
+ TransitRouteStop routeStop = builder.build();
routeStop.setAwaitDepartureTime(true);
stops.add(routeStop);
}
diff --git a/src/main/java/org/matsim/contrib/gtfs/RouteType.java b/src/main/java/org/matsim/contrib/gtfs/RouteType.java
index 94b9d4b..dda353e 100644
--- a/src/main/java/org/matsim/contrib/gtfs/RouteType.java
+++ b/src/main/java/org/matsim/contrib/gtfs/RouteType.java
@@ -90,7 +90,8 @@ public enum RouteType {
SIGHTSEEING_TRAM_SERVICE(904, "Sightseeing Tram Service", TRAM),
SHUTTLE_TRAM_SERVICE(905, "Shuttle Tram Service", TRAM),
ALL_TRAM_SERVICE(906, "All Tram Services", TRAM),
-
+ OTHER_TRAM_SERVICE(907, "Other Tram Services", TRAM),
+
WATER_TRANSPORT_SERVICE(1000, "Water Transport Service", FERRY),
INTERNATIONAL_CAR_FERRY_SERVICE(1001, "International Car Ferry Service", FERRY),
NATIONAL_CAR_FERRY_SERVICE(1002, "National Car Ferry Service", FERRY),
diff --git a/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSim.java b/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSim.java
index 6e0a1f7..572b848 100644
--- a/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSim.java
+++ b/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSim.java
@@ -7,10 +7,13 @@
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.transformations.IdentityTransformation;
+import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.pt.transitSchedule.api.TransitScheduleWriter;
import com.conveyal.gtfs.GTFSFeed;
import com.conveyal.gtfs.model.Route;
+import org.matsim.pt.utils.CreatePseudoNetwork;
+import org.matsim.pt.utils.CreateVehiclesForSchedule;
/**
* @author NKuehnel
@@ -52,6 +55,23 @@ public static void convertGtfs(String fromFile, String toFile, LocalDate date, C
System.out.println("Done.");
}
+ public static void convertGTFSandAddToScenario(Scenario scenario, String gtfsZip, LocalDate date, CoordinateTransformation coordinateTransformation, boolean createNetworkAndVehicles) {
+ GTFSFeed feed = GTFSFeed.fromFile(gtfsZip);
+ feed.feedInfo.values().stream().findFirst().ifPresent((feedInfo) -> {
+ System.out.println("Feed start date: " + feedInfo.feed_start_date);
+ System.out.println("Feed end date: " + feedInfo.feed_end_date);
+ });
+ GtfsConverter converter = new GtfsConverter(feed, scenario, coordinateTransformation, false);
+ converter.setDate(date);
+ converter.convert();
+ TransitSchedulePostProcessTools.copyLateDeparturesToStartOfDay(scenario.getTransitSchedule(), 86400.0, "copied", false);
+ TransitSchedulePostProcessTools.copyEarlyDeparturesToFollowingNight(scenario.getTransitSchedule(), 21600.0, "copied");
+ if (createNetworkAndVehicles) {
+ (new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), "pt_")).createNetwork();
+ (new CreateVehiclesForSchedule(scenario.getTransitSchedule(), scenario.getTransitVehicles())).run();
+ }
+ }
+
public static void main(String[] args) {
String inputZipFile = args[0];
String outputFile = args[1];
diff --git a/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSimExample.java b/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSimExample.java
index 812b141..ecfc5f7 100644
--- a/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSimExample.java
+++ b/src/main/java/org/matsim/contrib/gtfs/RunGTFS2MATSimExample.java
@@ -34,6 +34,7 @@
import org.matsim.pt.transitSchedule.api.TransitScheduleWriter;
import org.matsim.pt.utils.CreatePseudoNetwork;
import org.matsim.pt.utils.CreateVehiclesForSchedule;
+import org.matsim.vehicles.MatsimVehicleWriter;
import org.matsim.vehicles.VehicleWriterV1;
/**
@@ -41,47 +42,37 @@
* This is an example script that utilizes GTFS2MATSim and creates a pseudo network and vehicles using MATSim standard API functionality.
*/
-public class RunGTFS2MATSimExample {
+public final class RunGTFS2MATSimExample {
+
+ private RunGTFS2MATSimExample() {
+ }
-
public static void main(String[] args) {
//this was tested for the latest VBB GTFS, available at
// http://www.vbb.de/de/article/fahrplan/webservices/datensaetze/1186967.html
//input data
- String gtfsZipFile = "631760.zip";
+ String gtfsZipFile = "";
CoordinateTransformation ct = TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84, "EPSG:25833");
- LocalDate date = LocalDate.parse("2017-11-10");
+ LocalDate date = LocalDate.parse("2020-06-25");
//output files
String scheduleFile = "transitSchedule.xml.gz";
String networkFile = "network.xml.gz";
String transitVehiclesFile ="transitVehicles.xml.gz";
-
- //Convert GTFS
- RunGTFS2MATSim.convertGtfs(gtfsZipFile, scheduleFile, date, ct, false);
-
- //Parse the schedule again
Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
- new TransitScheduleReader(scenario).readFile(scheduleFile);
-
+
+ //Convert GTFS
+ RunGTFS2MATSim.convertGTFSandAddToScenario(scenario,gtfsZipFile,date,ct,true);
+
// copy late/early departures to have at complete schedule from ca. 0:00 to ca. 30:00
TransitSchedulePostProcessTools.copyLateDeparturesToStartOfDay(scenario.getTransitSchedule(), 24 * 3600, "copied", false);
TransitSchedulePostProcessTools.copyEarlyDeparturesToFollowingNight(scenario.getTransitSchedule(), 6 * 3600, "copied");
-
- //if neccessary, parse in an existing network file here:
-// new MatsimNetworkReader(scenario.getNetwork()).readFile("network.xml");
-
- //Create a network around the schedule
- new CreatePseudoNetwork(scenario.getTransitSchedule(),scenario.getNetwork(),"pt_").createNetwork();
-
- //Create simple transit vehicles
- new CreateVehiclesForSchedule(scenario.getTransitSchedule(), scenario.getTransitVehicles()).run();
-
+
//Write out network, vehicles and schedule
new NetworkWriter(scenario.getNetwork()).write(networkFile);
new TransitScheduleWriter(scenario.getTransitSchedule()).writeFile(scheduleFile);
- new VehicleWriterV1(scenario.getTransitVehicles()).writeFile(transitVehiclesFile);
+ new MatsimVehicleWriter(scenario.getTransitVehicles()).writeFile(transitVehiclesFile);
}
}
diff --git a/src/main/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessTools.java b/src/main/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessTools.java
index aa89388..691d8c3 100644
--- a/src/main/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessTools.java
+++ b/src/main/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessTools.java
@@ -62,7 +62,7 @@ public static void copyLateDeparturesToStartOfDay(TransitSchedule schedule, doub
for (Departure dep: route.getDepartures().values()) {
double oldDepartureTime = dep.getDepartureTime();
// do not copy Departures which arrive before midnight ()
- double arrivalAtLastStop = dep.getDepartureTime() + route.getStops().get(route.getStops().size() - 1).getArrivalOffset();
+ double arrivalAtLastStop = dep.getDepartureTime() + route.getStops().get(route.getStops().size() - 1).getArrivalOffset().seconds();
if (oldDepartureTime > startTimeOfCopying &&
(departureExclusionMarker== null || !dep.getId().toString().contains(departureExclusionMarker)) &&
(copyDespiteArrivalBeforeMidnight || arrivalAtLastStop >= 24*3600) ) {
diff --git a/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java b/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java
index 7334766..72189ed 100644
--- a/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java
+++ b/src/test/java/org/matsim/contrib/gtfs/GtfsTest.java
@@ -64,8 +64,8 @@ private void compareTransitSchedules(MutableScenario sc1, MutableScenario sc2) {
Assert.assertEquals(tr1.getTransportMode(), tr2.getTransportMode());
for(TransitRouteStop trStop: tr1.getStops()){
Assert.assertEquals(trStop.isAwaitDepartureTime(), tr2.getStops().get(tr1.getStops().indexOf(trStop)).isAwaitDepartureTime());
- Assert.assertEquals(trStop.getDepartureOffset(), tr2.getStops().get(tr1.getStops().indexOf(trStop)).getDepartureOffset(), 0.0);
- Assert.assertEquals(trStop.getArrivalOffset(), tr2.getStops().get(tr1.getStops().indexOf(trStop)).getArrivalOffset(), 0.0);
+ Assert.assertEquals(trStop.getDepartureOffset().seconds(), tr2.getStops().get(tr1.getStops().indexOf(trStop)).getDepartureOffset().seconds(), 0.0);
+ Assert.assertEquals(trStop.getArrivalOffset().seconds(), tr2.getStops().get(tr1.getStops().indexOf(trStop)).getArrivalOffset().seconds(), 0.0);
}
Assert.assertEquals(tr1.getDepartures().size(), tr2.getDepartures().size());
}
diff --git a/src/test/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessToolsTest.java b/src/test/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessToolsTest.java
index 339cca9..d5647ba 100644
--- a/src/test/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessToolsTest.java
+++ b/src/test/java/org/matsim/contrib/gtfs/TransitSchedulePostProcessToolsTest.java
@@ -174,8 +174,8 @@ public DepartureCopyingFixture() {
NetworkRoute networkRoute = RouteUtils.createLinkNetworkRouteImpl(firstStopLinkId, new ArrayList>(), lastStopLinkId);
List stopsRed = new ArrayList<>(2);
- stopsRed.add(sf.createTransitRouteStop(firstStop, Time.getUndefinedTime(), 0.0));
- stopsRed.add(sf.createTransitRouteStop(lastStop, 600, Time.getUndefinedTime()));
+ stopsRed.add(sf.createTransitRouteStopBuilder(firstStop).departureOffset(0.0).build());
+ stopsRed.add(sf.createTransitRouteStopBuilder(lastStop).arrivalOffset(600).build());
TransitRoute redABRoute = sf.createTransitRoute(Id.create("redFirstToLast", TransitRoute.class), networkRoute, stopsRed, "hoovercraft");
redABRoute.addDeparture(sf.createDeparture(Id.create("early", Departure.class), 6.0*3600));
redABRoute.addDeparture(sf.createDeparture(Id.create("midday", Departure.class), 12.0*3600));