From 000d3d0db959077c7b1af17f22d36726611b7f51 Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Fri, 29 Dec 2023 20:49:25 +0800 Subject: [PATCH] stash work in progress --- .../java/com/conveyal/gtfs/GeometryCache.java | 2 +- .../r5/analyst/cluster/AnalysisWorker.java | 8 ++ .../r5/analyst/cluster/SelectedLink.java | 75 +++++++++++++++++++ .../com/conveyal/r5/transit/TransitLayer.java | 1 + 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/conveyal/r5/analyst/cluster/SelectedLink.java diff --git a/src/main/java/com/conveyal/gtfs/GeometryCache.java b/src/main/java/com/conveyal/gtfs/GeometryCache.java index 96fa31635..642b8a46e 100644 --- a/src/main/java/com/conveyal/gtfs/GeometryCache.java +++ b/src/main/java/com/conveyal/gtfs/GeometryCache.java @@ -19,7 +19,7 @@ * LoadingCache so should be thread safe and provide granular per-key locking, which is convenient when serving up * lots of simultaneous vector tile requests. * - * This is currently used only for looking up geomertries when producing Mapbox vector map tiles, hence the single + * This is currently used only for looking up geometries when producing Mapbox vector map tiles, hence the single * set of hard-wired cache eviction parameters. For more general use we'd want another constructor to change them. */ public class GeometryCache { diff --git a/src/main/java/com/conveyal/r5/analyst/cluster/AnalysisWorker.java b/src/main/java/com/conveyal/r5/analyst/cluster/AnalysisWorker.java index 2add61702..91563d55f 100644 --- a/src/main/java/com/conveyal/r5/analyst/cluster/AnalysisWorker.java +++ b/src/main/java/com/conveyal/r5/analyst/cluster/AnalysisWorker.java @@ -498,6 +498,14 @@ protected void handleOneRegionalTask (RegionalTask task) throws Throwable { oneOriginResult = new OneOriginResult(null, new AccessibilityResult(task), null, null); } + // Post-process the OneOriginResult to filter paths down to only those passing through the selected links. + // The set of routes and stop pairs concerned are precalculated and retained on per regional analysis. + // The first thing to do is specify the point of interest on the request. selectedLink: {lat, lon, radiusMeters} + // Without precomputing anything ... just do the geometric calculations every time. And memoize the results. + transportNetwork.transitLayer.tripPatterns.getFirst().shape; + transportNetwork.transitLayer.tripPatterns.getFirst().getHopGeometries(); + + // Accumulate accessibility results, which will be returned to the backend in batches. // For most regional analyses, this is an accessibility indicator value for one of many origins, // but for static sites the indicator value is not known, it is computed in the UI. We still want to return diff --git a/src/main/java/com/conveyal/r5/analyst/cluster/SelectedLink.java b/src/main/java/com/conveyal/r5/analyst/cluster/SelectedLink.java new file mode 100644 index 000000000..4f636e01a --- /dev/null +++ b/src/main/java/com/conveyal/r5/analyst/cluster/SelectedLink.java @@ -0,0 +1,75 @@ +package com.conveyal.r5.analyst.cluster; + +import com.conveyal.r5.transit.TransitLayer; +import com.conveyal.r5.transit.TransportNetworkCache; +import com.conveyal.r5.transit.TripPattern; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.geom.LineString; + +import java.util.List; + +/** + * For Selected Link Analysis. + * + * Simplifications: + * Assumes all trips on the same pattern have the same geometry. + * + * TripPattern.getHopGeometries usually returns straight lines because TripPattern.shape is null (it is hard-wired to + * not save shapes in TransitLayers). However, the GTFS MapDBs should have the shapes for each trip. This is how we + * show them in GtfsController making VectorMapTiles. In fact we already have spatial index capabilities: + * gtfsCache.patternShapes.queryEnvelope(bundleScopedFeedId, tile.envelope) + * See L206-209 of GtfsController. However this does not retain enough information about the segments between stops + * in the patterns, and uses a lot of space for all those geometries. + * + * We'll need to turn on shape storage in the TripPatterns, or otherwise iterate through all of them in a streaming + * fashion to record every one that passes through the bounding box. + * + * Do the workers have access to the GTFS files or not? + * WorkerComponents has a TransportNetworkCache which is injected into the AnalysisWorker constructor. This is the only + * path to access a GtfsCache which is private, so we need a method on TransportNetworkCache. + */ +public class SelectedLink { + + public SelectedLink (TransportNetworkCache transportNetworkCache, SelectionBox box) { + for (TripPattern pattern : transit.tripPatterns) { + for (LineString hopGeoms : pattern.getHopGeometries(transit)) { + + } + } + } + + public SelectedLink (SelectionBox box, TransitLayer transit) { + for (TripPattern pattern : transit.tripPatterns) { + for (LineString hopGeoms : pattern.getHopGeometries(transit)) { + + } + } + } + + /** + * An alternate way of specifying a bounding box where there is a central point of interest and a margin of error + * around it. Some points at the corners of the bounding box are farther away than the radius (which is the radius + * of a circle inscribed in the bounding box). + */ + public static class SelectionBox { + double lon; + double lat; + double radiusMeters; + public Envelope toEnvelope () { + Envelope env = new Envelope(); + env.expandToInclude(lon, lat); + env.expandBy(radiusMeters); // FIXME convert to lon and lat degrees + } + } + + /** + * Uniquely identifies a segment between two subsequent stops on a TripPattern. + * This allows us to record in advance which segments pass through the link selection box. + */ + public static class TripPatternSegment { + TripPattern tripPattern; + int tripPatternIndex; // The integer ID of this tripPattern as a Raptor "route" in R5 routing. + int fromStopIndex; // Not the GTFS stop sequence number, the internal R5 index within the pattern. + } + +} diff --git a/src/main/java/com/conveyal/r5/transit/TransitLayer.java b/src/main/java/com/conveyal/r5/transit/TransitLayer.java index 871491ff2..34eab0ea5 100644 --- a/src/main/java/com/conveyal/r5/transit/TransitLayer.java +++ b/src/main/java/com/conveyal/r5/transit/TransitLayer.java @@ -288,6 +288,7 @@ public void loadFromGtfs (GTFSFeed gtfs, LoadLevel level) throws DuplicateFeedEx String patternId = gtfs.patternForTrip.get(tripId); + // Note that patternIds are UUIDs so should be unique even across different feeds. TripPattern tripPattern = tripPatternForPatternId.get(patternId); if (tripPattern == null) { tripPattern = new TripPattern(String.format("%s:%s", gtfs.feedId, route.route_id), stopTimes, indexForUnscopedStopId);