Skip to content

Commit

Permalink
Restrict access to "destination" for living streets in Hungary (by la…
Browse files Browse the repository at this point in the history
  • Loading branch information
Yogurt4 authored Apr 15, 2024
1 parent 474251f commit f7ef630
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package com.graphhopper.routing.util.countryrules.europe;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.RoadAccess;
import com.graphhopper.routing.ev.RoadClass;
import com.graphhopper.routing.ev.Toll;
import com.graphhopper.routing.util.TransportationMode;
import com.graphhopper.routing.util.countryrules.CountryRule;

/**
Expand All @@ -29,6 +31,26 @@
*/
public class HungaryCountryRule implements CountryRule {

@Override
public RoadAccess getAccess(ReaderWay readerWay, TransportationMode transportationMode, RoadAccess currentRoadAccess) {
// Pedestrian traffic and bicycles are not restricted
if (transportationMode == TransportationMode.FOOT || transportationMode == TransportationMode.BIKE) {
return currentRoadAccess;
}

// Override only bogus "yes" and missing/other
if (currentRoadAccess != RoadAccess.YES && currentRoadAccess != RoadAccess.OTHER) {
return currentRoadAccess;
}

RoadClass roadClass = RoadClass.find(readerWay.getTag("highway", ""));
if (roadClass == RoadClass.LIVING_STREET) {
return RoadAccess.DESTINATION;
}

return currentRoadAccess;
}

@Override
public Toll getToll(ReaderWay readerWay, Toll currentToll) {
if (currentToll != Toll.MISSING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.RoadAccess;
import com.graphhopper.routing.ev.Toll;
import com.graphhopper.routing.util.TransportationMode;
import com.graphhopper.routing.util.countryrules.europe.AustriaCountryRule;
import com.graphhopper.routing.util.countryrules.europe.GermanyCountryRule;
import com.graphhopper.routing.util.countryrules.europe.HungaryCountryRule;

import org.junit.jupiter.api.Test;

Expand All @@ -44,6 +46,25 @@ void austria() {
assertEquals(RoadAccess.DESTINATION, rule.getAccess(createReaderWay("living_street"), TransportationMode.CAR, RoadAccess.YES));
}

@Test
void hungary() {
HungaryCountryRule rule = new HungaryCountryRule();
assertEquals(RoadAccess.YES, rule.getAccess(createReaderWay("primary"), TransportationMode.CAR, RoadAccess.YES));
assertEquals(RoadAccess.DESTINATION, rule.getAccess(createReaderWay("living_street"), TransportationMode.CAR, RoadAccess.YES));
assertEquals(RoadAccess.YES, rule.getAccess(createReaderWay("living_street"), TransportationMode.BIKE, RoadAccess.YES));
assertEquals(RoadAccess.PRIVATE, rule.getAccess(createReaderWay("living_street"), TransportationMode.CAR, RoadAccess.PRIVATE));
assertEquals(RoadAccess.PRIVATE, rule.getAccess(createReaderWay("living_street"), TransportationMode.BIKE, RoadAccess.PRIVATE));
assertEquals(Toll.ALL, rule.getToll(createReaderWay("motorway"), Toll.MISSING));
assertEquals(Toll.HGV, rule.getToll(createReaderWay("trunk"), Toll.MISSING));
assertEquals(Toll.HGV, rule.getToll(createReaderWay("primary"), Toll.MISSING));
assertEquals(Toll.MISSING, rule.getToll(createReaderWay("secondary"), Toll.MISSING));
assertEquals(Toll.MISSING, rule.getToll(createReaderWay("residential"), Toll.MISSING));
assertEquals(Toll.MISSING, rule.getToll(createReaderWay("service"), Toll.MISSING));
assertEquals(Toll.ALL, rule.getToll(createReaderWay("service"), Toll.ALL));
assertEquals(Toll.HGV, rule.getToll(createReaderWay("service"), Toll.HGV));
assertEquals(Toll.NO, rule.getToll(createReaderWay("service"), Toll.NO));
}

private ReaderWay createReaderWay(String highway) {
ReaderWay readerWay = new ReaderWay(123L);
readerWay.setTag("highway", highway);
Expand Down

0 comments on commit f7ef630

Please sign in to comment.