Skip to content

Commit

Permalink
Merge pull request #780 from conveyal/tolerate-gtfs-extents
Browse files Browse the repository at this point in the history
Tolerate large GTFS geographic extents
  • Loading branch information
abyrd committed Jan 20, 2022
2 parents 83abf27 + 75adce5 commit f71de52
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -197,15 +199,26 @@ 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);
}
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()));
}

// 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;
Expand Down

0 comments on commit f71de52

Please sign in to comment.