Skip to content

Commit

Permalink
remove lane functionality from sumo converter, use DisallowedLinks in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
rakow committed Mar 27, 2024
1 parent a334faf commit fd4377a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public final class CreateNetworkFromSumo implements MATSimAppCommand {
@CommandLine.Option(names = "--output", description = "Output xml file", required = true)
private Path output;

@CommandLine.Mixin
private final ShpOptions shp = new ShpOptions();

@CommandLine.Mixin
private final CrsOptions crs = new CrsOptions();

Expand All @@ -67,36 +64,21 @@ public final class CreateNetworkFromSumo implements MATSimAppCommand {
@CommandLine.Option(names = "--free-speed-factor", description = "Free-speed reduction for urban links")
private double freeSpeedFactor = LinkProperties.DEFAULT_FREESPEED_FACTOR;

@CommandLine.Option(names = "--lane-restrictions", description = "Define how restricted lanes are handled: ${COMPLETION-CANDIDATES}", defaultValue = "IGNORE")
private SumoNetworkConverter.LaneRestriction laneRestriction = SumoNetworkConverter.LaneRestriction.IGNORE;

public static void main(String[] args) {
System.exit(new CommandLine(new CreateNetworkFromSumo()).execute(args));
}

@Override
public Integer call() throws Exception {

// since ShpOptions.getShapeFile() no longer is a path but a string, we have to check if it is defined before creating SumoNetworkConverter to
// preserve the possibility to run the converter without a shp file, otherwise, when calling Path.of(shp.getShapeFile) a NullPointerException is caused -sme0324
Path path = null;

if (shp.isDefined()) {
path = Path.of(shp.getShapeFile());
}

SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, path, crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor);
SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor, laneRestriction);

Network network = NetworkUtils.createNetwork();
Lanes lanes = LanesUtils.createLanesContainer();

SumoNetworkHandler handler = converter.convert(network, lanes);

converter.calculateLaneCapacities(network, lanes);

// This needs to run without errors, otherwise network is broken
network.getLinks().values().forEach(link -> {
LanesToLinkAssignment l2l = lanes.getLanesToLinkAssignments().get(link.getId());
if (l2l != null)
LanesUtils.createLanes(link, l2l);
});
SumoNetworkHandler handler = converter.convert(network);

if (capacities != null) {

Expand All @@ -105,21 +87,17 @@ public Integer call() throws Exception {
log.info("Read lane capacities from {}, containing {} lanes", capacities, map.size());

int n = setLinkCapacities(network, map);
int n2 = setLaneCapacities(lanes, map);

log.info("Unmatched links: {}, lanes: {}", n, n2);

log.info("Unmatched links: {}", n);
}

if (crs.getTargetCRS() != null)
ProjectionUtils.putCRS(network, crs.getTargetCRS());

NetworkUtils.writeNetwork(network, output.toAbsolutePath().toString());
new NetworkWriter(network).write(output.toAbsolutePath().toString());
new LanesWriter(lanes).write(output.toAbsolutePath().toString().replace(".xml", "-lanes.xml"));

converter.writeGeometry(handler, output.toAbsolutePath().toString().replace(".xml", "-linkGeometries.csv").replace(".gz", ""));

converter.writeFeatures(handler, output.toAbsolutePath().toString().replace(".xml", "-ft.csv"));

return 0;
Expand Down
Loading

0 comments on commit fd4377a

Please sign in to comment.