Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@ class AddFerryAccessMotorVehicle : OsmElementQuestType<Boolean>, AndroidQuest {
tags["motor_vehicle"] = answer.toYesNo()
}

override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> {
// the quest shall not be asked for ways tagged with route=ferry that are part of a relation
// also tagged with route=ferry because that makes the former not actually a "real" ferry
// route (╯°□°)╯︵ ┻━┻. Tagging mistake or not, it is very common tagging (#6373)
val wayIdsInFerryRoutes = wayIdsInFerryRoutes(mapData.relations)
return mapData
override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> = mapData
.filter(filter)
.filter { it !is Way || it.id !in wayIdsInFerryRoutes }
.asIterable()
}

override fun isApplicableTo(element: Element): Boolean? {
if (!filter.matches(element)) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ class AddFerryAccessPedestrian : OsmElementQuestType<Boolean>, AndroidQuest {
tags["foot"] = answer.toYesNo()
}

override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> {
// see comment in AddFerryAccessMotorVehicle
val wayIdsInFerryRoutes = wayIdsInFerryRoutes(mapData.relations)
return mapData
override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> = mapData
.filter(filter)
.filter { it !is Way || it.id !in wayIdsInFerryRoutes }
.asIterable()
}

override fun isApplicableTo(element: Element): Boolean? {
if (!filter.matches(element)) return false
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
package de.westnordost.streetcomplete.quests.max_weight

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Relation
import de.westnordost.streetcomplete.data.osm.mapdata.Way
import de.westnordost.streetcomplete.data.osm.mapdata.filter
import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.quest.AndroidQuest
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CAR
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.quests.ferry.wayIdsInFerryRoutes

class AddMaxWeight : OsmElementQuestType<MaxWeightAnswer>, AndroidQuest {
class AddMaxWeight : OsmFilterQuestType<MaxWeightAnswer>(), AndroidQuest {

// We ask for the maximum weight of bridges and ferries.
// The general filter is used for both:
private val generalFilter by lazy {
"""ways, relations with
!maxweight and maxweight:signed != no
override val elementFilter = """
ways with
highway ~ trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|residential|living_street|service|busway
and bridge and bridge != no
and service != driveway
and !maxweight and maxweight:signed != no
and !maxaxleload
and !maxbogieweight
and !maxweight:hgv and !maxweight:bus and !maxweight:hgv_articulated and !maxweight:tourist_bus and !maxweight:coach
and !maxweightrating and !maxweightrating:hgv and !maxweightrating:bus and !hgv
and !maxunladenweight and !maxunladenweight:hgv and !maxunladenweight:bus
and motor_vehicle !~ private|no
and vehicle !~ private|no
and (access !~ private|no or (foot and foot !~ private|no))
and area != yes
""".toElementFilterExpression() }

private val highwayFilter by lazy {
"""ways with
highway ~ trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|residential|living_street|service|busway
and bridge and bridge != no
and service != driveway
and motor_vehicle !~ private|no
""".toElementFilterExpression() }

private val ferryFilter by lazy {
"""ways, relations with
route = ferry
and motor_vehicle = yes
""".toElementFilterExpression() }

"""
override val changesetComment = "Specify maximum allowed weights"
override val wikiLink = "Key:maxweight"
override val icon = R.drawable.quest_max_weight
Expand All @@ -65,29 +45,4 @@ class AddMaxWeight : OsmElementQuestType<MaxWeightAnswer>, AndroidQuest {
}
}
}

override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> {
// copied from AddFerryAccessMotorVehicle - see comment there why this filtering is necessary
val wayIdsInFerryRoutes = wayIdsInFerryRoutes(mapData.relations)
return mapData
.filter(generalFilter)
.filter { ferryFilter.matches(it) || highwayFilter.matches(it) }
.filter { it !is Way || it.id !in wayIdsInFerryRoutes }
.asIterable()
}

override fun isApplicableTo(element: Element): Boolean? {
if (!generalFilter.matches(element)) return false
if (element is Way) {
if (highwayFilter.matches(element)) return true
// This way may be part of a ferry relation, in which case we will not ask
if (ferryFilter.matches(element)) return null
return false
}
if (element is Relation) {
// Highway relations are not matched
return ferryFilter.matches(element)
}
return false
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry
import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometryEntry
import de.westnordost.streetcomplete.data.osm.geometry.ElementPointGeometry
import de.westnordost.streetcomplete.util.SpatialCache
import de.westnordost.streetcomplete.util.ktx.geometryType
import de.westnordost.streetcomplete.util.math.contains
import de.westnordost.streetcomplete.util.math.isCompletelyInside
import kotlinx.atomicfu.locks.ReentrantLock
Expand Down Expand Up @@ -453,6 +454,23 @@ class MapDataCache(
if (spatialCache.size >= maxTiles && tilesToFetch.isNotEmpty()) {
trim((maxTiles * 2) / 3)
}

// Remove all ways tagged with route=ferry that are part of a relation
// also tagged with route=ferry because that makes the former not actually a "real" ferry
// route (╯°□°)╯︵ ┻━┻. Tagging mistake or not, it is very common tagging (#6373)
for (relation in result.relations) {
if (relation.tags["route"] != "ferry") continue
for (member in relation.members) {
if (member.type != ElementType.WAY) continue
val way = result.getWay(member.ref) ?: continue
val newTags = way.tags.toMutableMap()
newTags.remove("route")
result.putElement(
way.copy(tags = newTags)
)
}
}

return result
}

Expand Down