Search in sources :

Example 41 with OsmLatLon

use of de.westnordost.osmapi.map.data.OsmLatLon in project StreetComplete by westnordost.

the class ElementGeometryTest method testFindCenterOfPolylineWithZeroLength.

public void testFindCenterOfPolylineWithZeroLength() {
    List<List<LatLon>> polylines = new ArrayList<>();
    List<LatLon> polyline = new ArrayList<>();
    polyline.add(new OsmLatLon(20, 20));
    polyline.add(new OsmLatLon(20, 20));
    polylines.add(polyline);
    ElementGeometry geom = new ElementGeometry(polylines, null);
    assertEquals(null, geom.center);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 42 with OsmLatLon

use of de.westnordost.osmapi.map.data.OsmLatLon in project StreetComplete by westnordost.

the class ElementGeometryTest method createSquareAroundOrigin.

private static List<LatLon> createSquareAroundOrigin(double offsetLat, double offsetLon) {
    List<LatLon> square = new ArrayList<>();
    square.add(new OsmLatLon(-offsetLat, -offsetLon));
    square.add(new OsmLatLon(+offsetLat, -offsetLon));
    square.add(new OsmLatLon(+offsetLat, +offsetLon));
    square.add(new OsmLatLon(-offsetLat, +offsetLon));
    square.add(new OsmLatLon(-offsetLat, -offsetLon));
    return square;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 43 with OsmLatLon

use of de.westnordost.osmapi.map.data.OsmLatLon 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 44 with OsmLatLon

use of de.westnordost.osmapi.map.data.OsmLatLon in project StreetComplete by westnordost.

the class ElementGeometryDao method createObjectFrom.

static ElementGeometry createObjectFrom(Serializer serializer, Cursor cursor) {
    int colGeometryPolygons = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.GEOMETRY_POLYGONS), colGeometryPolylines = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.GEOMETRY_POLYLINES), colCenterLat = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.LATITUDE), colCenterLon = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.LONGITUDE);
    List<List<LatLon>> polygons = null, polylines = null;
    if (!cursor.isNull(colGeometryPolygons)) {
        polygons = serializer.toObject(cursor.getBlob(colGeometryPolygons), ArrayList.class);
    }
    if (!cursor.isNull(colGeometryPolylines)) {
        polylines = serializer.toObject(cursor.getBlob(colGeometryPolylines), ArrayList.class);
    }
    LatLon center = new OsmLatLon(cursor.getDouble(colCenterLat), cursor.getDouble(colCenterLon));
    return new ElementGeometry(polylines, polygons, center);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) ArrayList(java.util.ArrayList) List(java.util.List) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 45 with OsmLatLon

use of de.westnordost.osmapi.map.data.OsmLatLon in project StreetComplete by westnordost.

the class NodeDao method createObjectFrom.

@Override
protected Node createObjectFrom(Cursor cursor) {
    int colId = cursor.getColumnIndexOrThrow(NodeTable.Columns.ID), colLat = cursor.getColumnIndexOrThrow(NodeTable.Columns.LATITUDE), colLon = cursor.getColumnIndexOrThrow(NodeTable.Columns.LONGITUDE), colVersion = cursor.getColumnIndexOrThrow(NodeTable.Columns.VERSION), colTags = cursor.getColumnIndexOrThrow(NodeTable.Columns.TAGS);
    long id = cursor.getLong(colId);
    int version = cursor.getInt(colVersion);
    LatLon latLon = new OsmLatLon(cursor.getDouble(colLat), cursor.getDouble(colLon));
    Map<String, String> tags = null;
    if (!cursor.isNull(colTags)) {
        tags = serializer.toObject(cursor.getBlob(colTags), HashMap.class);
    }
    return new OsmNode(id, version, latLon, tags);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) HashMap(java.util.HashMap) OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Aggregations

OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)61 LatLon (de.westnordost.osmapi.map.data.LatLon)33 ArrayList (java.util.ArrayList)24 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)9 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)9 Date (java.util.Date)8 List (java.util.List)8 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)7 Note (de.westnordost.osmapi.notes.Note)6 OsmNode (de.westnordost.osmapi.map.data.OsmNode)5 TestQuestType (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType)5 Element (de.westnordost.osmapi.map.data.Element)4 TestQuestType2 (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)4 Node (de.westnordost.osmapi.map.data.Node)3 NoteComment (de.westnordost.osmapi.notes.NoteComment)3 HashMap (java.util.HashMap)3 Point (android.graphics.Point)2 Rect (android.graphics.Rect)2 LongSparseArray (android.util.LongSparseArray)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2