From bdda17f4450e4fad66b2402252552491ec0ea68f Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Tue, 4 Feb 2025 18:06:04 +0100 Subject: [PATCH] remove invalid tracktype (fixes #6116) --- .../osm/surface/SurfaceCreator.kt | 18 ++++++++++------ .../osm/surface/SurfaceCreatorKtTest.kt | 21 +++++++++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreator.kt b/app/src/main/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreator.kt index 6775472e329..deb51acbd96 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreator.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreator.kt @@ -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) } } diff --git a/app/src/test/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreatorKtTest.kt b/app/src/test/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreatorKtTest.kt index d5d473707fa..045e99d2062 100644 --- a/app/src/test/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreatorKtTest.kt +++ b/app/src/test/java/de/westnordost/streetcomplete/osm/surface/SurfaceCreatorKtTest.kt @@ -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")) ) } @@ -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")),