Skip to content

Commit

Permalink
split way: also remove "incline" if it is a number
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Oct 15, 2020
1 parent a92cac3 commit 9acee27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,16 @@ private fun Relation.findVias(relationType: String): List<RelationMember> {
* be incorrect now */
private fun MutableMap<String, String>.transformTagsForSplit() {
remove("step_count")

// only remove "incline" if it contains a number
val inclineNumberRegex = Regex("[0-9]")
val inclineValue = get("incline")
if (inclineValue != null && inclineNumberRegex.containsMatchIn(inclineValue)) remove("incline")

// only remove if "steps" is a number cause it is apparently also used to denote kind of steps
if (get("steps")?.toIntOrNull() != null) remove("steps")
remove("seats")

// remove any capacity: "capacity", "bicycle_parking:capacity", "parking:lane:both:capacity", "parking:lane:right:capacity:disabled" etc.
val capacityRegex = Regex("^(.*:)?capacity(:.*)?$")
val keysToDelete = keys.filter { capacityRegex.matches(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,30 +171,35 @@ class SplitSingleWayUploaderTest {

@Test fun `split way deletes tags that may be wrong after split`() {
val tags = mapOf(
"highway" to "residential",
"surface" to "asphalt",
"seats" to "55",
"step_count" to "12",
"steps" to "4",
"capacity" to "33",
"parking:lane:both:capacity" to "5",
"parking:lane:both:capacity:disabled" to "1",
"capacity:fat_persons" to "1",
"capacityaspartofaname:yes" to "ok",
"aspartofanamecapacity:yes" to "ok",
"incline" to "5.1%"
)
way = OsmWay(0,1, mutableListOf(0,1,2,3), tags)

val expectedTags = mapOf(
"highway" to "residential",
"surface" to "asphalt",
val elements = doSplit(SplitAtPoint(p[1]))
for (way in elements.ways) {
assertEquals(mapOf<String, String>(), way.tags)
}
}

@Test fun `split way does not delets tags that may be wrong after split under certain conditions`() {
val tags = mapOf(
"capacityaspartofaname:yes" to "ok",
"aspartofanamecapacity:yes" to "ok"
"aspartofanamecapacity:yes" to "ok",
"steps" to "yes",
"incline" to "up"
)
way = OsmWay(0,1, mutableListOf(0,1,2,3), tags)

val elements = doSplit(SplitAtPoint(p[1]))
for (way in elements.ways) {
assertEquals(expectedTags, way.tags)
assertEquals(tags, way.tags)
}
}

Expand Down

0 comments on commit 9acee27

Please sign in to comment.