Search in sources :

Example 16 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry in project StreetComplete by westnordost.

the class ElementCreatorTestGeometry method testCreateForWayWithDuplicateNodes.

public void testCreateForWayWithDuplicateNodes() {
    ElementGeometry geom = createCreator().create(W4);
    assertNotNull(geom.polylines);
    assertNotNull(geom.center);
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry)

Example 17 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry in project StreetComplete by westnordost.

the class OsmQuestDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    LatLon pos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry node4 = new ElementWithGeometry();
    node4.element = new OsmNode(4, 0, pos, null);
    node4.geometry = new ElementGeometry(pos);
    // questType mock will only "find" the Node #4
    OsmElementQuestType questType = new ListBackedQuestType(Collections.singletonList(node4));
    // in the quest database mock, there are quests for node 4 and node 5
    List<OsmQuest> quests = new ArrayList<>();
    quests.add(new OsmQuest(12L, questType, Element.Type.NODE, 4, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    quests.add(new OsmQuest(13L, questType, Element.Type.NODE, 5, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    when(osmQuestDao.getAll(any(BoundingBox.class), any(QuestStatus.class), anyString(), any(Element.Type.class), anyLong())).thenReturn(quests);
    doAnswer(invocation -> {
        Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
        assertEquals(1, deletedQuests.size());
        assertEquals(13L, (long) deletedQuests.iterator().next());
        return 1;
    }).when(osmQuestDao).deleteAll(any(Collection.class));
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    // -> we expect that quest with node #5 is removed
    dl.download(questType, new BoundingBox(0, 0, 1, 1), null);
    verify(osmQuestDao).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Matchers.anyLong(org.mockito.Matchers.anyLong) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 18 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry in project StreetComplete by westnordost.

the class AddRoadName method applyAnswerTo.

public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) {
    if (answer.getBoolean(AddRoadNameForm.NO_NAME)) {
        changes.add("noname", "yes");
        return;
    }
    int noProperRoad = answer.getInt(AddRoadNameForm.NO_PROPER_ROAD);
    if (noProperRoad != 0) {
        if (noProperRoad == AddRoadNameForm.IS_SERVICE)
            changes.modify("highway", "service");
        else if (noProperRoad == AddRoadNameForm.IS_TRACK)
            changes.modify("highway", "track");
        else if (noProperRoad == AddRoadNameForm.IS_LINK) {
            String prevValue = changes.getPreviousValue("highway");
            if (prevValue.matches("primary|secondary|tertiary")) {
                changes.modify("highway", prevValue + "_link");
            }
        }
        return;
    }
    String[] names = answer.getStringArray(AddRoadNameForm.NAMES);
    String[] languages = answer.getStringArray(AddRoadNameForm.LANGUAGE_CODES);
    HashMap<String, String> roadNameByLanguage = toRoadNameByLanguage(names, languages);
    for (Map.Entry<String, String> e : roadNameByLanguage.entrySet()) {
        if (e.getKey().isEmpty()) {
            changes.add("name", e.getValue());
        } else {
            changes.add("name:" + e.getKey(), e.getValue());
        }
    }
    // these params are passed from the form only to update the road name suggestions so that
    // newly input street names turn up in the suggestions as well
    long wayId = answer.getLong(AddRoadNameForm.WAY_ID);
    ElementGeometry geometry = (ElementGeometry) answer.getSerializable(AddRoadNameForm.WAY_GEOMETRY);
    if (geometry != null && geometry.polylines != null && !geometry.polylines.isEmpty()) {
        roadNameSuggestionsDao.putRoad(wayId, roadNameByLanguage, new ArrayList<>(geometry.polylines.get(0)));
    }
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry in project StreetComplete by westnordost.

the class ElementGeometryCreator method createMultipolygonGeometry.

private ElementGeometry createMultipolygonGeometry(Relation relation) {
    List<List<LatLon>> rings = new ArrayList<>();
    rings.addAll(createNormalizedRingGeometry(relation, "outer", false));
    rings.addAll(createNormalizedRingGeometry(relation, "inner", true));
    // no valid geometry
    if (rings.isEmpty())
        return null;
    ElementGeometry result = new ElementGeometry(null, rings);
    if (result.center == null)
        return null;
    return result;
}
Also used : ArrayList(java.util.ArrayList) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry in project StreetComplete by westnordost.

the class ElementGeometryCreator method createPolylinesGeometry.

private ElementGeometry createPolylinesGeometry(Relation relation) {
    List<List<LatLon>> waysNodePositions = getWaysOfRelationWithRole(relation, null);
    ConnectedWays ways = joinWays(waysNodePositions);
    List<List<LatLon>> polylines = ways.rest;
    polylines.addAll(ways.rings);
    // no valid geometry
    if (polylines.isEmpty())
        return null;
    ElementGeometry result = new ElementGeometry(polylines, null);
    if (result.center == null)
        return null;
    return result;
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)28 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)11 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)9 ArrayList (java.util.ArrayList)9 LatLon (de.westnordost.osmapi.map.data.LatLon)7 List (java.util.List)6 TestQuestType (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType)5 TestQuestType2 (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)4 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)3 Element (de.westnordost.osmapi.map.data.Element)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 OsmNode (de.westnordost.osmapi.map.data.OsmNode)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 Collection (java.util.Collection)2 Date (java.util.Date)2 Node (de.westnordost.osmapi.map.data.Node)1 Relation (de.westnordost.osmapi.map.data.Relation)1 Way (de.westnordost.osmapi.map.data.Way)1