Skip to content

Commit

Permalink
remove invalid tracktype (fixes #6116)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Feb 4, 2025
1 parent 141ac49 commit bdda17f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ fun Surface.applyTo(tags: Tags, prefix: String? = null, updateCheckDate: Boolean
val key = "${pre}surface"
val previousOsmValue = tags[key]
val hasChanged = previousOsmValue != null && previousOsmValue != osmValue
val hasChangedSurfaceCategory =
hasChanged && parseSurfaceCategory(osmValue) != parseSurfaceCategory(previousOsmValue)
val invalidTracktype =
prefix == null && osmValue in INVALID_SURFACES_FOR_TRACKTYPES[tags["tracktype"]].orEmpty()

// category of surface changed -> likely that tracktype is not correct anymore
// if tracktype and surface don't match at all, also delete tracktype
if (prefix == null && (hasChangedSurfaceCategory || invalidTracktype)) {
tags.remove("tracktype")
tags.removeCheckDatesForKey("tracktype")
}

// on change need to remove keys associated with (old) surface
if (hasChanged) {
// category of surface changed -> likely that tracktype is not correct anymore
if (prefix == null && parseSurfaceCategory(osmValue) != parseSurfaceCategory(previousOsmValue)) {
tags.remove("tracktype")
tags.removeCheckDatesForKey("tracktype")
}
// on change need to remove keys associated with (old) surface
getKeysAssociatedWithSurface(pre).forEach { tags.remove(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SurfaceCreatorKtTest {
@Test fun `don't remove tracktype when surface was added`() {
assertEquals(
setOf(StringMapEntryAdd("surface", "asphalt")),
ASPHALT.appliedTo(mapOf("tracktype" to "grade5",))
ASPHALT.appliedTo(mapOf("tracktype" to "grade2"))
)
}

Expand All @@ -73,11 +73,28 @@ class SurfaceCreatorKtTest {
setOf(StringMapEntryModify("surface", "concrete", "asphalt")),
ASPHALT.appliedTo(mapOf(
"surface" to "concrete",
"tracktype" to "grade5",
"tracktype" to "grade2",
))
)
}

@Test fun `remove mismatching tracktype`() {
assertEquals(
setOf(
StringMapEntryAdd("surface", "asphalt"),
StringMapEntryDelete("tracktype", "grade3")
),
ASPHALT.appliedTo(mapOf("tracktype" to "grade3"))
)
assertEquals(
setOf(
StringMapEntryAdd("surface", "dirt"),
StringMapEntryDelete("tracktype", "grade2")
),
DIRT.appliedTo(mapOf("tracktype" to "grade2"))
)
}

@Test fun `remove mismatching tracktype not done with prefix`() {
assertEquals(
setOf(StringMapEntryModify("footway:surface", "compacted", "asphalt")),
Expand Down

0 comments on commit bdda17f

Please sign in to comment.