Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion java-r5rcore/src/org/ipea/r5r/Network/NetworkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.conveyal.analysis.datasource.DataSourceException;
import com.conveyal.gtfs.GTFSFeed;
import com.conveyal.osmlib.OSM;
import com.conveyal.r5.analyst.cluster.TransportNetworkConfig;
import com.conveyal.r5.analyst.scenario.RasterCost;
import com.conveyal.r5.kryo.KryoNetworkSerializer;
import com.conveyal.r5.streets.StreetLayer;
Expand All @@ -21,6 +22,7 @@
import java.util.stream.Stream;

public class NetworkBuilder {
public static final String JSON_CONFIG_FILE = "config.json";

public static boolean useNativeElevation = false;
public static String elevationCostFunction = "NONE";
Expand All @@ -31,6 +33,8 @@ public class NetworkBuilder {
private static OSM osmFile;
private static Stream<GTFSFeed> gtfsFeeds;
private static String tiffFile = "";
private static TransportNetworkConfig transportNetworkConfig = null;


public static TransportNetwork checkAndLoadR5Network(String dataFolder) throws Exception {
File file = new File(dataFolder, "network.dat");
Expand Down Expand Up @@ -102,20 +106,23 @@ private static Map<String, String> buildNetworkConfig() {
networkConfig.put("elevation_cost_function", elevationCostFunction);
networkConfig.put("tiff_file_name", tiffFile);

networkConfig.put("transportNetworkConfig", transportNetworkConfig != null ? JSON_CONFIG_FILE : null);

return networkConfig;
}

private static TransportNetwork createNetwork() {
TransportNetwork network = new TransportNetwork();

network.scenarioId = "r5r";
network.streetLayer = new StreetLayer();
network.streetLayer = new StreetLayer(transportNetworkConfig);
network.streetLayer.loadFromOsm(osmFile);
osmFile.close();

network.streetLayer.parentNetwork = network;
network.streetLayer.indexStreets();

// currently the TransitLayer has no config, so we do not pass in networkConfig
network.transitLayer = new TransitLayerWithShapes();

gtfsFeeds.forEach(gtfsFeed -> {
Expand Down Expand Up @@ -185,6 +192,15 @@ public static void loadDirectory(File directory) {
}
if (name.endsWith(".zip")) gtfsFiles.add(file.getAbsolutePath());
if (name.endsWith(".tif") | name.endsWith(".tiff")) tiffFile = file.getAbsolutePath();
if (name.equals(JSON_CONFIG_FILE)) {
try {
// Use the R5 object mapper to make sure R5 config files are compatible (e.g. same case conventions)
transportNetworkConfig = com.conveyal.analysis.util.JsonUtil.objectMapper.readValue(file, TransportNetworkConfig.class);
} catch (Exception e) {
// re-throw, don't silently ignore a config file
throw new RuntimeException(e);
}
}
}

// Supply feeds with a stream, so they do not sit open in memory while other feeds are being processed.
Expand Down
31 changes: 20 additions & 11 deletions r-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,27 @@ start_r5r_java <- function(data_path,
fileurl <- fileurl_from_metadata( r5r_env$r5_jar_version )
filename <- basename(fileurl)

jar_file <- data.table::fifelse(
temp_dir,
file.path(tempdir(), filename),
file.path( r5r_env$cache_dir, filename)
)

# If there isn't a JAR already larger than 60MB, download it
if (checkmate::test_file_exists(jar_file) && file.info(jar_file)$size > r5r_env$r5_jar_size) {
if (!verbose) message("Using cached R5 version from ", jar_file)
if (is.null(getOption("r5r.r5jar"))) {
jar_file <- data.table::fifelse(
temp_dir,
file.path(tempdir(), filename),
file.path( r5r_env$cache_dir, filename)
)

# If there isn't a JAR already larger than 60MB, download it
if (checkmate::test_file_exists(jar_file) && file.info(jar_file)$size > r5r_env$r5_jar_size) {
if (!verbose) message("Using cached R5 version from ", jar_file)
} else {
check <- download_r5(temp_dir = temp_dir, quiet = !verbose)
if (is.null(check)) { return(invisible(NULL)) }
}
} else {
check <- download_r5(temp_dir = temp_dir, quiet = !verbose)
if (is.null(check)) { return(invisible(NULL)) }
jar_file <- getOption("r5r.r5jar")
if (checkmate::test_file_exists(jar_file)) {
message("Overriding default R5 with option r5r.r5jar, using ", jar_file)
} else {
stop(paste0("Cannot find r5 jar \"", jar_file, "\", specified in options(r5r.r5jar)"))
}
}

# R5 jar
Expand Down
Binary file modified r-package/inst/jar/r5r.jar
Binary file not shown.
Loading