Skip to content

Commit

Permalink
filter irrelevant nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jun 4, 2024
1 parent ea80c2a commit 1b66270
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CreateAvroNetwork implements MATSimAppCommand {
@CommandLine.Option(names = "--match-id", description = "Pattern to filter links by id")
private String matchId;

@CommandLine.Option(names = "--mode-filter", split = ",", defaultValue = "car,freight,drt",
@CommandLine.Option(names = "--mode-filter", split = ",", defaultValue = "car,bike,truck,freight,drt",
description = "Only keep links if they have one of the specified modes. Specify 'none' to disable.")
private Set<String> modes;

Expand Down Expand Up @@ -136,6 +136,15 @@ private void convert(AvroNetwork avro, Network network, CoordinateTransformation
Set<CharSequence> nodeAttributes = new LinkedHashSet<>();

for (Node node : network.getNodes().values()) {

List<Link> relevant = new ArrayList<>();
relevant.addAll(node.getInLinks().values());
relevant.addAll(node.getOutLinks().values());

// Skip nodes without relevant links
if (relevant.stream().noneMatch(filter))
continue;

Coord from = ct.transform(node.getCoord());
double xCoord = round(from.getX());
double yCoord = round(from.getY());
Expand All @@ -152,7 +161,6 @@ private void convert(AvroNetwork avro, Network network, CoordinateTransformation
avro.setNodeIds(nodeIds.keySet().stream().toList());
avro.setNodeAttributes(nodeAttributes.stream().toList());


// Link attributes
FloatList lengths = new FloatArrayList();
FloatList freeSpeeds = new FloatArrayList();
Expand Down

0 comments on commit 1b66270

Please sign in to comment.