-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bus Stop Name Suggestions, generalize Name Suggestions (#6097)
Add Bus Stop Name Suggestions Resolves #5187 --------- Co-authored-by: Flo Edelmann <[email protected]> Co-authored-by: Tobias Zwick <[email protected]>
- Loading branch information
1 parent
05b8ace
commit 86256a6
Showing
11 changed files
with
146 additions
and
88 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
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/de/westnordost/streetcomplete/quests/NameSuggestionsSource.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,54 @@ | ||
package de.westnordost.streetcomplete.quests | ||
|
||
import de.westnordost.streetcomplete.data.elementfilter.ElementFilterExpression | ||
import de.westnordost.streetcomplete.data.osm.edits.MapDataWithEditsSource | ||
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon | ||
import de.westnordost.streetcomplete.data.osm.mapdata.filter | ||
import de.westnordost.streetcomplete.osm.LocalizedName | ||
import de.westnordost.streetcomplete.osm.parseLocalizedNames | ||
import de.westnordost.streetcomplete.util.math.distance | ||
import de.westnordost.streetcomplete.util.math.enclosingBoundingBox | ||
import de.westnordost.streetcomplete.util.math.enlargedBy | ||
|
||
class NameSuggestionsSource(private val mapDataSource: MapDataWithEditsSource) { | ||
/** | ||
* Return a list of [LocalizedName]s of elements with name(s), sorted by distance ascending to | ||
* any of the given [points] that have at most a distance of [maxDistance] in m to those. The | ||
* elements can be filtered with the given [filter] expression, to e.g. only find | ||
* roads with names. | ||
*/ | ||
fun getNames( | ||
points: List<LatLon>, | ||
maxDistance: Double, | ||
filter: ElementFilterExpression | ||
): List<List<LocalizedName>> { | ||
if (points.isEmpty()) return emptyList() | ||
|
||
/* add 100m radius for bbox query because roads will only be included in the result that | ||
have at least one node in the bounding box around the tap position. This is a problem for | ||
long straight roads (#3797). This doesn't completely solve this issue but mitigates it */ | ||
val bbox = points.enclosingBoundingBox().enlargedBy(maxDistance + 100) | ||
val mapData = mapDataSource.getMapDataWithGeometry(bbox) | ||
val filteredElements = mapData.filter(filter) | ||
// map of localized names -> min distance | ||
val result = mutableMapOf<List<LocalizedName>, Double>() | ||
|
||
for (element in filteredElements) { | ||
val geometry = mapData.getGeometry(element.type, element.id) ?: continue | ||
|
||
val minDistance = points.minOf { geometry.distance(it) } | ||
if (minDistance > maxDistance) continue | ||
|
||
val names = parseLocalizedNames(element.tags) ?: continue | ||
|
||
// eliminate duplicates (e.g. same road, different segments, different distances) | ||
val prev = result[names] | ||
if (prev != null && prev < minDistance) continue | ||
|
||
result[names] = minDistance | ||
} | ||
|
||
// return only the road names, sorted by distance ascending | ||
return result.entries.sortedBy { it.value }.map { it.key } | ||
} | ||
} |
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
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
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
57 changes: 0 additions & 57 deletions
57
...src/main/java/de/westnordost/streetcomplete/quests/road_name/RoadNameSuggestionsSource.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.