Skip to content

Commit 3cfcb6d

Browse files
committed
Return scenario buffer extents
using existing scenarioApplicationInfo field
1 parent f2a9d33 commit 3cfcb6d

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/main/java/com/conveyal/analysis/models/Bounds.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ public static Bounds fromWgsEnvelope (Envelope envelope) {
3535
return bounds;
3636
}
3737

38+
public String toJsonString (double factor) {
39+
return String.format("\"north\": %f, \"south\": %f, \"east\": %f, \"west\": %f",
40+
north / factor,
41+
south / factor,
42+
east / factor,
43+
west / factor);
44+
}
45+
3846
}

src/main/java/com/conveyal/r5/analyst/scenario/Scenario.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
1616
import java.util.Comparator;
17+
import java.util.HashMap;
1718
import java.util.List;
1819
import java.util.Map;
1920

@@ -153,6 +154,17 @@ public TransportNetwork applyToTransportNetwork (TransportNetwork originalNetwor
153154
copiedNetwork.streetLayer.scenarioEdgesBoundingGeometry(TransitLayer.WALK_DISTANCE_LIMIT_METERS);
154155
copiedNetwork.transitLayer.buildDistanceTables(treeRebuildZone);
155156

157+
// Custom feature for Caltrans: applies mode-specific buffer distances around modifications (for now, only
158+
// those that affect street layer)
159+
if (this.affectsStreetLayer()) {
160+
Map<String, Integer> buffersByMode = new HashMap<>();
161+
buffersByMode.put("Walk", 7200);
162+
buffersByMode.put("Bike", 24000);
163+
buffersByMode.put("Transit", 50000);
164+
buffersByMode.put("Car", 112000);
165+
copiedNetwork.addScenarioBuffers(buffersByMode);
166+
}
167+
156168
// Find the transfers originating at or terminating at new stops.
157169
// TODO also rebuild transfers which are near street network changes but which do not connect to new stops.
158170
new TransferFinder(copiedNetwork).findTransfers();

src/main/java/com/conveyal/r5/transit/TransportNetwork.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.conveyal.r5.transit;
22

3+
import com.conveyal.analysis.models.Bounds;
34
import com.conveyal.gtfs.GTFSFeed;
45
import com.conveyal.osmlib.OSM;
56
import com.conveyal.r5.analyst.LinkageCache;
67
import com.conveyal.r5.analyst.WebMercatorGridPointSet;
78
import com.conveyal.r5.analyst.cluster.TransportNetworkConfig;
89
import com.conveyal.r5.analyst.error.TaskError;
910
import com.conveyal.r5.analyst.fare.InRoutingFareCalculator;
11+
import com.conveyal.r5.analyst.scenario.Modification;
12+
import com.conveyal.r5.analyst.scenario.ModifyStreets;
1013
import com.conveyal.r5.analyst.scenario.Scenario;
1114
import com.conveyal.r5.common.JsonUtilities;
1215
import com.conveyal.r5.kryo.KryoNetworkSerializer;
@@ -32,6 +35,8 @@
3235
import java.util.zip.ZipEntry;
3336
import java.util.zip.ZipFile;
3437

38+
import static com.conveyal.r5.streets.VertexStore.FIXED_FACTOR;
39+
3540
/**
3641
* This is a completely new replacement for Graph, Router etc.
3742
* It uses a lot less object pointers and can be built, read, and written orders of magnitude faster.
@@ -376,6 +381,16 @@ public TransportNetwork scenarioCopy(Scenario scenario) {
376381
return copy;
377382
}
378383

384+
public void addScenarioBuffers(Map<String, Integer> buffersByMode) {
385+
List<String> bufferInfo = new ArrayList<>();
386+
bufferInfo.add("Buffers for all modifications tied to street layer:");
387+
buffersByMode.forEach((mode, distance) -> {
388+
Envelope customExtents = streetLayer.scenarioEdgesBoundingGeometry(distance).getEnvelopeInternal();
389+
bufferInfo.add(mode +"\n " + Bounds.fromWgsEnvelope(customExtents).toJsonString(FIXED_FACTOR));
390+
});
391+
this.scenarioApplicationInfo.add(new TaskError(new ModifyStreets(), bufferInfo));
392+
}
393+
379394
/**
380395
* FIXME why is this a long when crc32 returns an int?
381396
* @return a checksum of the graph, for use in verifying whether it changed or remained the same after

0 commit comments

Comments
 (0)