Skip to content

Commit

Permalink
collecting street data for streetcomplete#213
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Nov 15, 2019
1 parent e0e4313 commit 66a18e5
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.westnordost.streetcomplete.data.QuestTypeRegistry;
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao;
import de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType;
import de.westnordost.streetcomplete.quests.address.AddAddressStreet;
import de.westnordost.streetcomplete.quests.baby_changing_table.AddBabyChangingTable;
import de.westnordost.streetcomplete.quests.bike_parking_capacity.AddBikeParkingCapacity;
import de.westnordost.streetcomplete.quests.bike_parking_cover.AddBikeParkingCover;
Expand Down Expand Up @@ -67,7 +68,7 @@
import de.westnordost.streetcomplete.quests.toilet_availability.AddToiletAvailability;
import de.westnordost.streetcomplete.quests.toilets_fee.AddToiletsFee;
import de.westnordost.streetcomplete.quests.tracktype.AddTracktype;
import de.westnordost.streetcomplete.quests.housenumber.AddHousenumber;
import de.westnordost.streetcomplete.quests.address.AddHousenumber;
import de.westnordost.streetcomplete.quests.max_speed.AddMaxSpeed;
import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHours;
import de.westnordost.streetcomplete.quests.localized_name.AddRoadName;
Expand Down Expand Up @@ -107,6 +108,7 @@ public class QuestModule
new AddBusStopName(o),
new AddIsBuildingUnderground(o), //to avoid asking AddHousenumber and other for underground buildings
new AddHousenumber(o),
new AddAddressStreet(o),
new MarkCompletedHighwayConstruction(o),
new AddReligionToPlaceOfWorship(o), // icons on maps are different - OSM Carto, mapy.cz, OsmAnd, Sputnik etc
new AddParkingAccess(o), //OSM Carto, mapy.cz, OSMand, Sputnik etc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.westnordost.streetcomplete.quests.address

import de.westnordost.osmapi.map.data.BoundingBox
import de.westnordost.osmapi.map.data.Element
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.OsmElementQuestType
import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.download.MapDataWithGeometryHandler
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao
import de.westnordost.streetcomplete.data.osm.tql.getQuestPrintStatement
import de.westnordost.streetcomplete.data.osm.tql.toGlobalOverpassBBox

class AddAddressStreet(private val overpassMapDataDao: OverpassMapDataDao) : OsmElementQuestType<AddressStreetAnswer> {
override val commitMessage = "Add address"
override val icon = R.drawable.ic_quest_label

override fun getTitle(tags: Map<String, String>) = R.string.quest_address_street_title

override fun createForm() = AddAddressStreetForm()

override fun download(bbox: BoundingBox, handler: MapDataWithGeometryHandler): Boolean {
return overpassMapDataDao.getAndHandleQuota(getOverpassQuery(bbox), handler);
}

override fun isApplicableTo(element: Element): Boolean? = null

override fun applyAnswerTo(answer: AddressStreetAnswer, changes: StringMapChangesBuilder) {
when(answer){
is StreetName -> {changes.add("addr:street", answer.name)}
is PlaceName -> {changes.add("addr:place", answer.name)}
}
}

private fun getOverpassQuery(bbox: BoundingBox) =
bbox.toGlobalOverpassBBox() + """
relation["type"="associatedStreet"];
> -> .inStreetRelation;
nwr["addr:street"!~".*"]["addr:housenumber"]["addr:place"!~".*"] -> .missing_data;
(.missing_data; - .inStreetRelation;);""" +
getQuestPrintStatement()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.westnordost.streetcomplete.quests.address

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment
import de.westnordost.streetcomplete.quests.OtherAnswer
import de.westnordost.streetcomplete.util.TextChangedWatcher
import kotlinx.android.synthetic.main.quest_placename.*

class AddAddressStreetForm : AbstractQuestFormAnswerFragment<AddressStreetAnswer>() {
override val contentLayoutResId = R.layout.quest_placename

override val otherAnswers = listOf(
OtherAnswer(R.string.quest_address_street_no_named_streets) { confirmNoName() }
)

private val placeName get() = nameInput?.text?.toString().orEmpty().trim()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

nameInput.addTextChangedListener(TextChangedWatcher { checkIsFormComplete() })
}

override fun onClickOk() {
applyAnswer(StreetName(placeName))
}

private fun confirmNoName() {
AlertDialog.Builder(activity!!)
.setTitle(R.string.quest_name_answer_noName_confirmation_title)
.setPositiveButton(R.string.quest_name_noName_confirmation_positive) { _, _ -> applyAnswer(PlaceName("TODO")) } //TODO!
.setNegativeButton(R.string.quest_generic_confirmation_no, null)
.show()
}

override fun isFormComplete() = placeName.isNotEmpty()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.westnordost.streetcomplete.quests.housenumber
package de.westnordost.streetcomplete.quests.address

import android.util.Log

Expand All @@ -21,7 +21,7 @@ import de.westnordost.streetcomplete.util.SphericalEarthMath

class AddHousenumber(private val overpass: OverpassMapDataDao) : OsmElementQuestType<HousenumberAnswer> {

override val commitMessage = "Add housenumbers"
override val commitMessage = "Add address"
override val icon = R.drawable.ic_quest_housenumber

// See overview here: https://ent8r.github.io/blacklistr/?streetcomplete=housenumber/AddHousenumber.kt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.westnordost.streetcomplete.quests.housenumber
package de.westnordost.streetcomplete.quests.address

import android.os.Bundle
import androidx.appcompat.app.AlertDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.westnordost.streetcomplete.quests.address

sealed class AddressStreetAnswer

data class StreetName(val name:String) : AddressStreetAnswer()
data class PlaceName(val name:String) : AddressStreetAnswer()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.westnordost.streetcomplete.quests.housenumber
package de.westnordost.streetcomplete.quests.address

sealed class HousenumberAnswer

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="about_contributing">Your answers are directly improving OpenStreetMap. Contributed data is open, everyone can use it. Many great projects are already using it.</string>
<string name="about_missing_stars">Currently, the star count is not shared across devices, but answers are added directly to the OpenStreetMap database.</string>
<string name="how_to_get_stars">Choose one of the markers on the map and answer the question. This way you will improve OpenStreetMap data and get stars. If you see no markers you may need to zoom out the map.</string>
<string name="quest_address_street_title">What is the street of this address?</string>
<string name="quest_address_street_no_named_streets">This address has no assigned named street</string>
<string name="quest_cyclewayPartSurface_title">What\'s the surface of the cycleway here?</string>
<string name="quest_footwayPartSurface_title">What\'s the surface of the footway here?</string>
<string name="quest_generic_answer_differs_along_the_way">"Differs along the way…"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.westnordost.streetcomplete.quests.add_housenumber
import de.westnordost.osmapi.map.data.BoundingBox
import de.westnordost.streetcomplete.IntegrationTests
import de.westnordost.streetcomplete.data.OsmModule
import de.westnordost.streetcomplete.quests.housenumber.AddHousenumber
import de.westnordost.streetcomplete.quests.address.AddHousenumber
import de.westnordost.streetcomplete.quests.verifyDownloadYieldsNoQuest
import org.junit.Test
import org.junit.experimental.categories.Category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.westnordost.streetcomplete.quests.add_housenumber

import de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd
import de.westnordost.streetcomplete.mock
import de.westnordost.streetcomplete.quests.housenumber.*
import de.westnordost.streetcomplete.quests.address.*
import de.westnordost.streetcomplete.quests.verifyAnswer
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
Expand Down

0 comments on commit 66a18e5

Please sign in to comment.