Skip to content

Commit

Permalink
stash work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Dec 29, 2023
1 parent ef9638b commit 000d3d0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/conveyal/gtfs/GeometryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Geometry> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/com/conveyal/r5/analyst/cluster/SelectedLink.java
Original file line number Diff line number Diff line change
@@ -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.
}

}
1 change: 1 addition & 0 deletions src/main/java/com/conveyal/r5/transit/TransitLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 000d3d0

Please sign in to comment.