-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3735 from arrival-spring/sidewalk-surface
Sidewalk surface quest
- Loading branch information
Showing
17 changed files
with
782 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...treetcomplete/quests/sidewalk/Sidewalk.kt → ...t/streetcomplete/osm/sidewalk/Sidewalk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/de/westnordost/streetcomplete/osm/sidewalk/SidewalkParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.westnordost.streetcomplete.osm.sidewalk | ||
|
||
import de.westnordost.streetcomplete.ktx.containsAny | ||
import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.NO | ||
import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.SEPARATE | ||
import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.YES | ||
|
||
|
||
data class LeftAndRightSidewalk(val left: Sidewalk?, val right: Sidewalk?) | ||
|
||
/** Returns on which sides are sidewalks. Returns null if tagging is unknown */ | ||
fun createSidewalkSides(tags: Map<String, String>): LeftAndRightSidewalk? { | ||
if (!tags.keys.containsAny(KNOWN_SIDEWALK_KEYS)) return null | ||
|
||
val sidewalk = createSidewalksDefault(tags) | ||
if (sidewalk != null) return sidewalk | ||
|
||
// alternative tagging | ||
val altSidewalk = createSidewalksAlternative(tags) | ||
if (altSidewalk != null) return altSidewalk | ||
|
||
return null | ||
} | ||
|
||
private fun createSidewalksDefault(tags: Map<String, String>): LeftAndRightSidewalk? = when(tags["sidewalk"]) { | ||
"left" -> LeftAndRightSidewalk(left = YES, right = NO) | ||
"right" -> LeftAndRightSidewalk(left = NO, right = YES) | ||
"both" -> LeftAndRightSidewalk(left = YES, right = YES) | ||
"no", "none" -> LeftAndRightSidewalk(left = NO, right = NO) | ||
"separate" -> LeftAndRightSidewalk(left = SEPARATE, right = SEPARATE) | ||
else -> null | ||
} | ||
|
||
private fun createSidewalksAlternative(tags: Map<String, String>): LeftAndRightSidewalk? { | ||
val sidewalkLeft = tags["sidewalk:both"] ?: tags["sidewalk:left"] | ||
val sidewalkRight = tags["sidewalk:both"] ?: tags["sidewalk:right"] | ||
return if (sidewalkLeft != null || sidewalkRight != null) { | ||
LeftAndRightSidewalk(left = createSidewalkSide(sidewalkLeft), right = createSidewalkSide(sidewalkRight)) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
private fun createSidewalkSide(tag: String?): Sidewalk? = when(tag) { | ||
"yes" -> YES | ||
"no" -> NO | ||
"separate" -> SEPARATE | ||
else -> null | ||
} | ||
|
||
private val KNOWN_SIDEWALK_KEYS = listOf( | ||
"sidewalk", "sidewalk:left", "sidewalk:right", "sidewalk:both" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/src/main/java/de/westnordost/streetcomplete/quests/sidewalk/AddSidewalkForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
app/src/main/java/de/westnordost/streetcomplete/quests/sidewalk/SidewalkItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
app/src/main/java/de/westnordost/streetcomplete/quests/surface/AddSidewalkSurface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package de.westnordost.streetcomplete.quests.surface | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.meta.SIDEWALK_SURFACE_KEYS | ||
import de.westnordost.streetcomplete.data.meta.hasCheckDateForKey | ||
import de.westnordost.streetcomplete.data.meta.removeCheckDatesForKey | ||
import de.westnordost.streetcomplete.data.meta.updateCheckDateForKey | ||
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType | ||
import de.westnordost.streetcomplete.data.osm.osmquests.Tags | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.PEDESTRIAN | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.WHEELCHAIR | ||
|
||
class AddSidewalkSurface : OsmFilterQuestType<SidewalkSurfaceAnswer>() { | ||
|
||
// Only roads with 'complete' sidewalk tagging (at least one side has sidewalk, other side specified) | ||
override val elementFilter = """ | ||
ways with | ||
highway ~ trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|residential | ||
and area != yes | ||
and motorroad != yes | ||
and ( | ||
sidewalk ~ both|left|right or | ||
sidewalk:both = yes or | ||
(sidewalk:left = yes and sidewalk:right ~ yes|no|separate) or | ||
(sidewalk:right = yes and sidewalk:left ~ yes|no|separate) | ||
) | ||
and ( | ||
${SIDEWALK_SURFACE_KEYS.joinToString(" and ") {"!$it"}} | ||
or sidewalk:surface older today -8 years | ||
) | ||
""" | ||
|
||
override val changesetComment = "Add surface of sidewalks" | ||
override val wikiLink = "Key:sidewalk" | ||
override val icon = R.drawable.ic_quest_sidewalk_surface | ||
override val isSplitWayEnabled = true | ||
override val questTypeAchievements = listOf(PEDESTRIAN, WHEELCHAIR) | ||
override val defaultDisabledMessage = R.string.default_disabled_msg_difficult_and_time_consuming | ||
|
||
override fun getTitle(tags: Map<String, String>) : Int = | ||
R.string.quest_sidewalk_surface_title | ||
|
||
override fun createForm() = AddSidewalkSurfaceForm() | ||
|
||
override fun applyAnswerTo(answer: SidewalkSurfaceAnswer, tags: Tags, timestampEdited: Long) { | ||
val leftChanged = answer.left?.let { sideSurfaceChanged(it, Side.LEFT, tags) } | ||
val rightChanged = answer.right?.let { sideSurfaceChanged(it, Side.RIGHT, tags) } | ||
|
||
if (leftChanged == true) { | ||
deleteSmoothnessKeys(Side.LEFT, tags) | ||
deleteSmoothnessKeys(Side.BOTH, tags) | ||
} | ||
if (rightChanged == true) { | ||
deleteSmoothnessKeys(Side.RIGHT, tags) | ||
deleteSmoothnessKeys(Side.BOTH, tags) | ||
} | ||
|
||
if (answer.left == answer.right) { | ||
answer.left?.let { applySidewalkSurfaceAnswerTo(it, Side.BOTH, tags) } | ||
deleteSidewalkSurfaceAnswerIfExists(Side.LEFT, tags) | ||
deleteSidewalkSurfaceAnswerIfExists(Side.RIGHT, tags) | ||
} else { | ||
answer.left?.let { applySidewalkSurfaceAnswerTo(it, Side.LEFT, tags) } | ||
answer.right?.let { applySidewalkSurfaceAnswerTo(it, Side.RIGHT, tags) } | ||
deleteSidewalkSurfaceAnswerIfExists(Side.BOTH, tags) | ||
} | ||
deleteSidewalkSurfaceAnswerIfExists(null, tags) | ||
|
||
// only set the check date if nothing was changed or if check date was already set | ||
if (!tags.hasChanges || tags.hasCheckDateForKey("sidewalk:surface")) { | ||
tags.updateCheckDateForKey("sidewalk:surface") | ||
} | ||
} | ||
|
||
private enum class Side(val value: String) { | ||
LEFT("left"), RIGHT("right"), BOTH("both") | ||
} | ||
|
||
private fun sideSurfaceChanged(surface: SurfaceAnswer, side: Side, tags: Tags): Boolean { | ||
val previousSideOsmValue = tags["sidewalk:${side.value}:surface"] | ||
val previousBothOsmValue = tags["sidewalk:both:surface"] | ||
val osmValue = surface.value.osmValue | ||
|
||
return previousSideOsmValue != null && previousSideOsmValue != osmValue | ||
|| previousBothOsmValue != null && previousBothOsmValue != osmValue | ||
} | ||
|
||
private fun applySidewalkSurfaceAnswerTo(surface: SurfaceAnswer, side: Side, tags: Tags) | ||
{ | ||
val sidewalkKey = "sidewalk:" + side.value | ||
val sidewalkSurfaceKey = "$sidewalkKey:surface" | ||
|
||
tags[sidewalkSurfaceKey] = surface.value.osmValue | ||
|
||
// add/remove note - used to describe generic surfaces | ||
if (surface.note != null) { | ||
tags["$sidewalkSurfaceKey:note"] = surface.note | ||
} else { | ||
tags.remove("$sidewalkSurfaceKey:note") | ||
} | ||
// clean up old source tags - source should be in changeset tags | ||
tags.remove("source:$sidewalkSurfaceKey") | ||
} | ||
|
||
/** clear smoothness tags for the given side*/ | ||
private fun deleteSmoothnessKeys(side: Side, tags: Tags) { | ||
val sidewalkKey = "sidewalk:" + side.value | ||
tags.remove("$sidewalkKey:smoothness") | ||
tags.remove("$sidewalkKey:smoothness:date") | ||
tags.removeCheckDatesForKey("$sidewalkKey:smoothness") | ||
} | ||
|
||
/** clear previous answers for the given side */ | ||
private fun deleteSidewalkSurfaceAnswerIfExists(side: Side?, tags: Tags) { | ||
val sideVal = if (side == null) "" else ":" + side.value | ||
val sidewalkSurfaceKey = "sidewalk$sideVal:surface" | ||
|
||
// only things are cleared that are set by this quest | ||
// for example cycleway:surface should only be cleared by a cycleway surface quest etc. | ||
tags.remove(sidewalkSurfaceKey) | ||
tags.remove("$sidewalkSurfaceKey:note") | ||
} | ||
|
||
} |
Oops, something went wrong.