diff --git a/src/main/java/org/matsim/prepare/commercial/TransferRestrictions.java b/src/main/java/org/matsim/prepare/commercial/TransferRestrictions.java index 7a7329a..c958d4d 100644 --- a/src/main/java/org/matsim/prepare/commercial/TransferRestrictions.java +++ b/src/main/java/org/matsim/prepare/commercial/TransferRestrictions.java @@ -5,6 +5,7 @@ import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.Node; import org.matsim.application.options.ShpOptions; import org.matsim.core.network.NetworkUtils; import org.matsim.core.utils.geometry.CoordUtils; @@ -25,15 +26,28 @@ public class TransferRestrictions { Transfers Restrictions from the shapefile to the given Network. */ - private static final String ruhrNetworkPath = "D:\\Projects\\VSP\\RUHR\\commercialTraffic\\ruhr_network.xml.gz"; + private static final String ruhrNetworkPath = "D:\\Projects\\VSP\\RUHR\\metropole-ruhr-v2.0.network_resolutionHigh-with-pt.xml"; private static final String restrictionPath = "D:\\Projects\\VSP\\RUHR\\commercialTraffic\\Restriktionen_RVR_20231121\\Restriktionen_RVR_20231121.shp"; private static final String outputPath = "scenarios/metropole-ruhr-v1.0/ruhr_network_with_restrictions.xml.gz"; public static void main(String[] args){ //Read in shp and xml files Network network = NetworkUtils.readNetwork(ruhrNetworkPath); + Network network_no_pt = NetworkUtils.createNetwork(); ShpOptions shp = new ShpOptions(Path.of(restrictionPath), null, null); + //Create copy of network which only contains links, where car/freight-traffic is allowed (not pt, no bike-only-links, ...) + for(Node n : network.getNodes().values()){ + if(!n.getId().toString().startsWith("pt") && !n.getId().toString().startsWith("bike")){ + network_no_pt.addNode(n); + } + } + for(Link l : network.getLinks().values()){ + if(l.getAllowedModes().contains("car") || l.getAllowedModes().contains("freight")){ + network_no_pt.addLink(l); + } + } + // Add all freight-modes to all car-links Collection links = network.getLinks().values(); Set all = new HashSet<>(Arrays.asList("freight", "truck8t", "truck18t", "truck26t", "truck40t")); @@ -60,10 +74,17 @@ public static void main(String[] args){ //Finds the center of two nodes and searches for the link from there if(j != 0){ Coord center = CoordUtils.getCenter(coord, coord); - Link nearestLink = NetworkUtils.getNearestLinkExactly(network, center); + Link nearestLink = NetworkUtils.getNearestLinkExactly(network_no_pt, center); Link oppositeLink = NetworkUtils.findLinkInOppositeDirection(nearestLink); Set allowedModes = new HashSet<>(nearestLink.getAllowedModes()); // Makes a copy, because original is immutable + //Sort out links, that were assigned incorrectly + double distance = NetworkUtils.getEuclideanDistance(nearestLink.getFromNode().getCoord(), center); + double links_euclidean_length = NetworkUtils.getEuclideanDistance(nearestLink.getFromNode().getCoord(), nearestLink.getToNode().getCoord()); + if(distance > links_euclidean_length+20){ + continue; + } + //Get value if numeric float value = -1; try{