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);
}
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));
}
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)));
}
}
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;
}
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;
}
Aggregations