From 9595319900d9fd4064beba1ee857656102b85d68 Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Wed, 19 Jan 2022 18:11:00 +0800 Subject: [PATCH 1/2] tolerate large GTFS geographic extents (#779) --- .../analysis/controllers/BundleController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/conveyal/analysis/controllers/BundleController.java b/src/main/java/com/conveyal/analysis/controllers/BundleController.java index 2cb8afd63..42cd25398 100644 --- a/src/main/java/com/conveyal/analysis/controllers/BundleController.java +++ b/src/main/java/com/conveyal/analysis/controllers/BundleController.java @@ -13,6 +13,8 @@ import com.conveyal.file.FileUtils; import com.conveyal.gtfs.GTFSCache; import com.conveyal.gtfs.GTFSFeed; +import com.conveyal.gtfs.error.GTFSError; +import com.conveyal.gtfs.error.GeneralError; import com.conveyal.gtfs.model.Stop; import com.conveyal.osmlib.Node; import com.conveyal.osmlib.OSM; @@ -205,7 +207,16 @@ private Bundle create (Request req, Response res) { for (Stop s : feed.stops.values()) { bundleBounds.expandToInclude(s.stop_lon, s.stop_lat); } - checkWgsEnvelopeSize(bundleBounds, "GTFS data"); + try { + checkWgsEnvelopeSize(bundleBounds, "GTFS data"); + } catch (IllegalArgumentException iae) { + // Convert envelope size or antimeridian crossing exceptions to feed import errors. + // Out of range lat/lon values will throw DataSourceException and bundle import will fail. + // Envelope size or antimeridian crossing will throw IllegalArgumentException. We want to + // soft-fail on these because some feeds contain small amounts of long-distance service + // which may extend far beyond the analysis area without causing problems. + feed.errors.add(new GeneralError("stops", -1, null, iae.getMessage())); + } if (bundle.serviceStart.isAfter(feedSummary.serviceStart)) { bundle.serviceStart = feedSummary.serviceStart; From 75adce5d5b33a6f078466ce91300f967d9347b7b Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Thu, 20 Jan 2022 14:26:13 +0800 Subject: [PATCH 2/2] Summarize feed only after adding all errors --- .../analysis/controllers/BundleController.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/conveyal/analysis/controllers/BundleController.java b/src/main/java/com/conveyal/analysis/controllers/BundleController.java index 42cd25398..0f73f2898 100644 --- a/src/main/java/com/conveyal/analysis/controllers/BundleController.java +++ b/src/main/java/com/conveyal/analysis/controllers/BundleController.java @@ -199,11 +199,7 @@ private Bundle create (Request req, Response res) { feed.progressListener = progressListener; feed.loadFromFile(zipFile, new ObjectId().toString()); - // Populate the metadata while the feed is open - // TODO also get service range, hours per day etc. and error summary (and complete error JSON). - Bundle.FeedSummary feedSummary = new Bundle.FeedSummary(feed, bundle.feedGroupId); - bundle.feeds.add(feedSummary); - + // Find and validate the extents of the GTFS, defined by all stops in the feed. for (Stop s : feed.stops.values()) { bundleBounds.expandToInclude(s.stop_lon, s.stop_lat); } @@ -218,6 +214,12 @@ private Bundle create (Request req, Response res) { feed.errors.add(new GeneralError("stops", -1, null, iae.getMessage())); } + // Populate the metadata while the feed is still open. + // This must be done after all errors have been added to the feed. + // TODO also get service range, hours per day etc. and error summary (and complete error JSON). + Bundle.FeedSummary feedSummary = new Bundle.FeedSummary(feed, bundle.feedGroupId); + bundle.feeds.add(feedSummary); + if (bundle.serviceStart.isAfter(feedSummary.serviceStart)) { bundle.serviceStart = feedSummary.serviceStart; }