Skip to content

Commit

Permalink
Also ask for height limits of crossings with rails electrified with o…
Browse files Browse the repository at this point in the history
…verhead wires (fixes #5180)
  • Loading branch information
westnordost committed Aug 17, 2023
1 parent c013568 commit 50d6f7e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class AddMaxHeight : OsmElementQuestType<MaxHeightAnswer> {
and !maxheight and !maxheight:signed and !maxheight:physical
""".toElementFilterExpression() }

private val railwayCrossingsFilter by lazy { """
nodes with
railway = level_crossing
and !maxheight and !maxheight:signed and !maxheight:physical
""".toElementFilterExpression() }

private val electrifiedRailwaysFilter by lazy { """
ways with
railway
and electrified = contact_line
""".toElementFilterExpression() }

private val allRoadsFilter by lazy { """
ways with highway ~ ${ALL_ROADS.joinToString("|")}
""".toElementFilterExpression() }
Expand Down Expand Up @@ -78,12 +90,22 @@ class AddMaxHeight : OsmElementQuestType<MaxHeightAnswer> {
.flatMapTo(HashSet()) { it.nodeIds }

val nodesWithoutHeight = mapData.nodes
.filter { roadsNodeIds.contains(it.id) && nodeFilter.matches(it) }
.filter { it.id in roadsNodeIds && nodeFilter.matches(it) }

// railway crossings with railways that have an electrified contact line
val electrifiedRailwayNodeIds = mapData.ways
.filter { electrifiedRailwaysFilter.matches(it) }
.flatMapTo(HashSet()) { it.nodeIds }

val railwayCrossingNodesWithoutHeight = mapData.nodes
.filter { it.id in electrifiedRailwayNodeIds && railwayCrossingsFilter.matches(it) }

// tunnels without height
val roadsWithoutHeight = mapData.ways.filter { roadsWithoutMaxHeightFilter.matches(it) }

val tunnelsWithoutHeight = roadsWithoutHeight.filter { tunnelFilter.matches(it) }

// ways below bridges without height
val bridges = mapData.ways.filter { bridgeFilter.matches(it) }

val waysBelowBridgesWithoutHeight = roadsWithoutHeight.filter { way ->
Expand All @@ -104,7 +126,10 @@ class AddMaxHeight : OsmElementQuestType<MaxHeightAnswer> {
}
}

return nodesWithoutHeight + tunnelsWithoutHeight + waysBelowBridgesWithoutHeight
return nodesWithoutHeight +
railwayCrossingNodesWithoutHeight +
tunnelsWithoutHeight +
waysBelowBridgesWithoutHeight
}

override fun isApplicableTo(element: Element): Boolean? {
Expand All @@ -117,6 +142,8 @@ class AddMaxHeight : OsmElementQuestType<MaxHeightAnswer> {
// for nodes that may be applicable we cannot finally determine it because that node must be
// a vertex of a road
if (nodeFilter.matches(element)) return null
// railway crossing
if (railwayCrossingsFilter.matches(element)) return null
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ class AddMaxHeightTest {
assertNull(questType.isApplicableTo(parkingEntrance))
}

@Test fun `applicable to railway crossing node that is a vertex of an electrified railway`() {
val crossing = node(2, tags = mapOf("railway" to "level_crossing"))
val railway = way(1, listOf(1, 2), mapOf(
"railway" to "rail",
"electrified" to "contact_line"
))

val mapData = TestMapDataWithGeometry(listOf(railway, crossing))

assertEquals(1, questType.getApplicableElements(mapData).toList().size)
assertNull(questType.isApplicableTo(crossing))
}

@Test fun `not applicable to railway crossing node that is a vertex of a normal railway`() {
val crossing = node(2, tags = mapOf("railway" to "level_crossing"))
val railway = way(1, listOf(1, 2), mapOf("railway" to "rail"))

val mapData = TestMapDataWithGeometry(listOf(railway, crossing))

assertEquals(0, questType.getApplicableElements(mapData).toList().size)
assertNull(questType.isApplicableTo(crossing))
}

@Test fun `applicable to road below bridge`() {
val mapData = TestMapDataWithGeometry(listOf(
way(1, listOf(1, 2), mapOf(
Expand Down

0 comments on commit 50d6f7e

Please sign in to comment.