Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify types of railways that constitute rail_access #2

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
2 changes: 0 additions & 2 deletions .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ policies:
body:
required: true
dco: false
gpg:
required: true
spellcheck:
locale: US
maximumOfOneCommit: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* This enum defines the railway class of an edge. It maps the railway=* key of OSM to an enum. All edges that do not fit get OTHER as value.
*/
public enum RailwayClass {
OTHER, RAIL, SUBWAY, TRAM, NARROW_GAUGE, LIGHT_RAIL, FUNICULAR;
OTHER, RAIL, SUBWAY, TRAM, NARROW_GAUGE, LIGHT_RAIL, FUNICULAR, CONSTRUCTION;

public static final String KEY = "railway_class";

Expand All @@ -29,4 +29,4 @@ public static RailwayClass find(String name) {
return OTHER;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.geofabrik.railway_routing.parsers;

import java.util.Set;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.EncodedValueLookup;
import com.graphhopper.routing.ev.VehicleAccess;
Expand All @@ -13,6 +15,9 @@
public class RailAccessParser extends AbstractAccessParser {

public static final String DEFAULT_NAME = "rail";
private static final Set<String> ALLOWED_RAIL_TYPES = Set.of(
"rail", "light_rail", "tram", "subway", "construction", "proposed", "funicular", "monorail"
);

public RailAccessParser(BooleanEncodedValue accessEnc) {
super(accessEnc, TransportationMode.TRAIN);
Expand All @@ -29,7 +34,7 @@ public WayAccess getAccess(ReaderWay way) {
if (railway == null) {
return WayAccess.CAN_SKIP;
}
if (railway.equals("rail") || railway.equals("light_rail") || railway.equals("tram") || railway.equals("subway") || railway.equals("narrow_gauge")) {
if (ALLOWED_RAIL_TYPES.contains(railway)) {
return WayAccess.WAY;
}
return WayAccess.CAN_SKIP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ void railwayClass() {
way.setTag("railway", "rail;tram");
parser.handleWayTags(edgeId, edgeIntAccess, way, relFlags);
assertEquals(RailwayClass.OTHER, classEnc.getEnum(false, edgeId, edgeIntAccess));

edgeIntAccess = new ArrayEdgeIntAccess(1);
way = new ReaderWay(29L);
way.setTag("railway", "construction");
parser.handleWayTags(edgeId, edgeIntAccess, way, relFlags);
assertEquals(RailwayClass.CONSTRUCTION, classEnc.getEnum(false, edgeId, edgeIntAccess));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public void testAcceptsTrack() {
assertEquals(e.getAccess(way), WayAccess.WAY);
}

@Test
public void testAcceptsConstruction() {
PMap properties = new PMap();
RailAccessParser e = createAccessParser(createEncodingManager(), properties);
ReaderWay way = new ReaderWay(1);
way.setTag("railway", "construction");
assertEquals(e.getAccess(way), WayAccess.WAY);
}

@Test
public void testRejectRoad() {
PMap properties = new PMap();
Expand All @@ -55,4 +64,13 @@ public void testRejectRoad() {
way.setTag("railway", "rail");
assertEquals(WayAccess.WAY, e.getAccess(way));
}

@Test
public void testRejectsNarrowGauge() {
PMap properties = new PMap();
RailAccessParser e = createAccessParser(createEncodingManager(), properties);
ReaderWay way = new ReaderWay(1);
way.setTag("railway", "narrow_gauge");
assertEquals(WayAccess.CAN_SKIP, e.getAccess(way));
}
}
Loading