Skip to content

Commit

Permalink
Fix check for invalid relation references
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 27, 2023
1 parent 5085fb3 commit 13607be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ private void processPublicTransportStopArea(OSMRelation relation) {
}
}
case WAY -> {
if (member.hasRolePlatform() && areaWayIds.contains(member.getRef())) {
if (member.hasRolePlatform() && areaWaysById.containsKey(member.getRef())) {
platformAreas.add(areaWaysById.get(member.getRef()));
}
}
Expand All @@ -1075,6 +1075,14 @@ private void processPublicTransportStopArea(OSMRelation relation) {
}

for (OSMWithTags area : platformAreas) {
if (area == null) {
throw new RuntimeException(
"Could not process public transport relation '%s' (%s)".formatted(
relation,
relation.url()
)
);
}
// single platform area presumably contains only one level in most cases
// a node inside it may specify several levels if it is an elevator
// make sure each node has access to the current platform level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public boolean hasTypeWay() {
return type == WAY;
}

public String url() {
return "https://www.openstreetmap.org/%s/%s".formatted(type.toString().toLowerCase(), ref);
}

@Override
public String toString() {
return "osm rel " + type + ":" + role + ":" + ref;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package org.opentripplanner.openstreetmap.model;
package org.opentripplanner.graph_builder.module.osm;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.osm.OsmDatabase;
import org.opentripplanner.openstreetmap.OsmProvider;

public class BicycleNetworkRelationsTest {
public class OsmDatabaseTest {

/* The way https://www.openstreetmap.org/way/13876983 does not contain the tag lcn (local cycling network)
* but because it is part of a relation that _does_, the tag is copied from the relation to the way.
* This test assert that this is really happening.
*/
@Test
public void testBicycleRouteRelations() {
var issueStore = DataImportIssueStore.NOOP;
var osmdb = new OsmDatabase(issueStore);
void bicycleRouteRelations() {
var osmdb = new OsmDatabase(DataImportIssueStore.NOOP);
var provider = new OsmProvider(
new File("src/test/resources/germany/ehningen-minimal.osm.pbf"),
true
Expand All @@ -32,4 +30,19 @@ public void testBicycleRouteRelations() {
assertEquals(way.getTag("lcn"), "yes");
assertEquals(way.getTag("name"), "Gärtringer Weg");
}

@Test
void invalidPublicTransportRelation() {
var osmdb = new OsmDatabase(DataImportIssueStore.NOOP);
var url = getClass().getResource("brenner-invalid-member-reference.osm.pbf");
assertNotNull(url);
var file = new File(url.getFile());
var provider = new OsmProvider(file, true);
provider.readOSM(osmdb);
osmdb.postLoad();

var way = osmdb.getWay(302732658L);
assertNotNull(way);
assertEquals(way.getTag("public_transport"), "platform");
}
}
Binary file not shown.

0 comments on commit 13607be

Please sign in to comment.