Search in sources :

Example 21 with ElementGeometry

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

the class OverpassMapDataParser method onEndElement.

@Override
protected void onEndElement() {
    String name = getName();
    Element element = null;
    ElementGeometry geometry = null;
    switch(name) {
        case MEMBER:
            wayNodes = null;
            break;
        case NODE:
            Node node = factory.createNode(id, version, lat, lon, tags, null, null);
            geometry = elementGeometryCreator.create(node);
            element = node;
            break;
        case WAY:
            Way way = factory.createWay(id, version, nodes, tags, null, null);
            geometry = elementGeometryCreator.create(way);
            element = way;
            nodes = null;
            nodePositionsByWay = null;
            wayNodes = null;
            break;
        case RELATION:
            Relation relation = factory.createRelation(id, version, members, tags, null, null);
            geometry = elementGeometryCreator.create(relation);
            element = relation;
            members = null;
            nodePositionsByWay = null;
            break;
    }
    if (element != null) {
        tags = null;
        handler.handle(element, geometry);
    }
}
Also used : Relation(de.westnordost.osmapi.map.data.Relation) Element(de.westnordost.osmapi.map.data.Element) Node(de.westnordost.osmapi.map.data.Node) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Way(de.westnordost.osmapi.map.data.Way)

Example 22 with ElementGeometry

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

the class AOsmQuestDao method createObjectFrom.

@Override
protected OsmQuest createObjectFrom(Cursor cursor) {
    int colQuestId = cursor.getColumnIndexOrThrow(Columns.QUEST_ID), colElementId = cursor.getColumnIndexOrThrow(Columns.ELEMENT_ID), colElementType = cursor.getColumnIndexOrThrow(Columns.ELEMENT_TYPE), colQuestStatus = cursor.getColumnIndexOrThrow(Columns.QUEST_STATUS), colQuestType = cursor.getColumnIndexOrThrow(Columns.QUEST_TYPE), colChanges = cursor.getColumnIndexOrThrow(Columns.TAG_CHANGES), colChangesSource = cursor.getColumnIndexOrThrow(Columns.CHANGES_SOURCE), colLastChange = cursor.getColumnIndexOrThrow(Columns.LAST_UPDATE);
    long questId = cursor.getLong(colQuestId);
    long elementId = cursor.getLong(colElementId);
    Element.Type elementType = Element.Type.valueOf(cursor.getString(colElementType));
    QuestStatus questStatus = QuestStatus.valueOf(cursor.getString(colQuestStatus));
    String questTypeName = cursor.getString(colQuestType);
    OsmElementQuestType questType = (OsmElementQuestType) questTypeRegistry.getByName(questTypeName);
    if (questType == null) {
        throw new IllegalArgumentException("The quest type " + questTypeName + " does not exist!");
    }
    StringMapChanges changes = null;
    if (!cursor.isNull(colChanges)) {
        changes = serializer.toObject(cursor.getBlob(colChanges), StringMapChanges.class);
    }
    String changesSource = null;
    if (!cursor.isNull(colChangesSource)) {
        changesSource = cursor.getString(colChangesSource);
    }
    ElementGeometry geometry = ElementGeometryDao.createObjectFrom(serializer, cursor);
    Date lastChange = new Date(cursor.getLong(colLastChange));
    return new OsmQuest(questId, questType, elementType, elementId, questStatus, changes, changesSource, lastChange, geometry);
}
Also used : OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date)

Example 23 with ElementGeometry

use of de.westnordost.streetcomplete.data.osm.ElementGeometry 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 24 with ElementGeometry

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

the class ElementGeometryDaoTest method testDeleteUnreferenced.

public void testDeleteUnreferenced() {
    Element.Type type = Element.Type.WAY;
    long id = 0;
    ElementGeometry geometry = createSimpleGeometry();
    dao.put(type, id, geometry);
    assertEquals(1, dao.deleteUnreferenced());
    dao.put(type, id, geometry);
    new OsmQuestDao(dbHelper, serializer, null).add(new OsmQuest(Mockito.mock(OsmElementQuestType.class), type, id, geometry));
    assertEquals(0, dao.deleteUnreferenced());
}
Also used : Element(de.westnordost.osmapi.map.data.Element) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Example 25 with ElementGeometry

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

the class ElementGeometryDaoTest method testSimplePutGet.

public void testSimplePutGet() {
    ElementGeometry geometry = createSimpleGeometry();
    dao.put(Element.Type.NODE, 0, geometry);
    ElementGeometry dbGeometry = dao.get(Element.Type.NODE, 0);
    assertEquals(geometry, dbGeometry);
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry)

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