Search in sources :

Example 1 with RelationMember

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

the class ElementGeometryCreator method getWaysOfRelationWithRole.

private List<List<LatLon>> getWaysOfRelationWithRole(Relation relation, String role) {
    List<List<LatLon>> result = new ArrayList<>();
    for (RelationMember member : relation.getMembers()) {
        if (member.getType() != Element.Type.WAY)
            continue;
        long wayId = member.getRef();
        if (role == null || role.equals(member.getRole())) {
            List<LatLon> nodePositions = data.getNodePositions(wayId);
            eliminateDuplicates(nodePositions);
            if (nodePositions.size() > 1) {
                result.add(nodePositions);
            }
        }
    }
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) RelationMember(de.westnordost.osmapi.map.data.RelationMember) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with RelationMember

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

the class OverpassMapDataParserTest method testRelation.

public void testRelation() {
    OsmLatLon[] p = new OsmLatLon[5];
    p[0] = new OsmLatLon(1, 2);
    p[1] = new OsmLatLon(3, 4);
    p[2] = new OsmLatLon(5, 6);
    p[3] = new OsmLatLon(7, 8);
    p[4] = new OsmLatLon(9, 10);
    String xml = "<relation id='10' version='1'>\n" + " <member type='relation' ref='4' role=''/>\n" + " <member type='way' ref='1' role='outer'>\n" + "  <nd lat='" + p[0].getLatitude() + "' lon='" + p[0].getLongitude() + "'/>\n" + "  <nd lat='" + p[1].getLatitude() + "' lon='" + p[1].getLongitude() + "'/>\n" + " </member>\n" + " <member type='way' ref='2' role='inner'>\n" + "  <nd lat='" + p[2].getLatitude() + "' lon='" + p[2].getLongitude() + "'/>\n" + "  <nd lat='" + p[3].getLatitude() + "' lon='" + p[3].getLongitude() + "'/>\n" + " </member>\n" + " <member type='node' ref='3' role='point'>\n" + "  <nd lat='" + p[4].getLatitude() + "' lon='" + p[4].getLongitude() + "'/>\n" + " </member>\n" + "</relation>";
    LongSparseArray<List<LatLon>> expectedGeometry = new LongSparseArray<>();
    expectedGeometry.put(1, new ArrayList<>(Arrays.asList(p[0], p[1])));
    expectedGeometry.put(2, new ArrayList<>(Arrays.asList(p[2], p[3])));
    Element e = parseOne(xml, expectedGeometry);
    assertTrue(e instanceof Relation);
    Relation relation = (Relation) e;
    assertEquals(10, relation.getId());
    assertEquals(1, relation.getVersion());
    assertEquals(4, relation.getMembers().size());
    RelationMember[] rm = new RelationMember[relation.getMembers().size()];
    relation.getMembers().toArray(rm);
    assertEquals(4, rm[0].getRef());
    assertEquals(Element.Type.RELATION, rm[0].getType());
    assertEquals("", rm[0].getRole());
    assertEquals(1, rm[1].getRef());
    assertEquals(Element.Type.WAY, rm[1].getType());
    assertEquals("outer", rm[1].getRole());
    assertEquals(2, rm[2].getRef());
    assertEquals(Element.Type.WAY, rm[2].getType());
    assertEquals("inner", rm[2].getRole());
    assertEquals(3, rm[3].getRef());
    assertEquals(Element.Type.NODE, rm[3].getType());
    assertEquals("point", rm[3].getRole());
    assertNull(relation.getTags());
}
Also used : LongSparseArray(android.util.LongSparseArray) Relation(de.westnordost.osmapi.map.data.Relation) RelationMember(de.westnordost.osmapi.map.data.RelationMember) Element(de.westnordost.osmapi.map.data.Element) ArrayList(java.util.ArrayList) List(java.util.List) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 3 with RelationMember

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

the class RelationDaoTest method testPutGetNoTags.

public void testPutGetNoTags() {
    List<RelationMember> members = new ArrayList<>();
    members.add(new OsmRelationMember(0, "outer", Element.Type.WAY));
    members.add(new OsmRelationMember(1, "inner", Element.Type.WAY));
    Relation relation = new OsmRelation(5, 1, members, null);
    dao.put(relation);
    Relation dbRelation = dao.get(5);
    checkEqual(relation, dbRelation);
}
Also used : Relation(de.westnordost.osmapi.map.data.Relation) OsmRelation(de.westnordost.osmapi.map.data.OsmRelation) OsmRelationMember(de.westnordost.osmapi.map.data.OsmRelationMember) RelationMember(de.westnordost.osmapi.map.data.RelationMember) OsmRelation(de.westnordost.osmapi.map.data.OsmRelation) ArrayList(java.util.ArrayList) OsmRelationMember(de.westnordost.osmapi.map.data.OsmRelationMember)

Example 4 with RelationMember

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

the class RelationDaoTest method testPutGetWithTags.

public void testPutGetWithTags() {
    List<RelationMember> members = new ArrayList<>();
    members.add(new OsmRelationMember(0, "outer", Element.Type.WAY));
    members.add(new OsmRelationMember(1, "inner", Element.Type.WAY));
    Map<String, String> tags = new HashMap<>();
    tags.put("a key", "a value");
    Relation relation = new OsmRelation(5, 1, members, tags);
    dao.put(relation);
    Relation dbRelation = dao.get(5);
    checkEqual(relation, dbRelation);
}
Also used : Relation(de.westnordost.osmapi.map.data.Relation) OsmRelation(de.westnordost.osmapi.map.data.OsmRelation) OsmRelationMember(de.westnordost.osmapi.map.data.OsmRelationMember) RelationMember(de.westnordost.osmapi.map.data.RelationMember) HashMap(java.util.HashMap) OsmRelation(de.westnordost.osmapi.map.data.OsmRelation) ArrayList(java.util.ArrayList) OsmRelationMember(de.westnordost.osmapi.map.data.OsmRelationMember)

Aggregations

RelationMember (de.westnordost.osmapi.map.data.RelationMember)4 ArrayList (java.util.ArrayList)4 Relation (de.westnordost.osmapi.map.data.Relation)3 OsmRelation (de.westnordost.osmapi.map.data.OsmRelation)2 OsmRelationMember (de.westnordost.osmapi.map.data.OsmRelationMember)2 List (java.util.List)2 LongSparseArray (android.util.LongSparseArray)1 Element (de.westnordost.osmapi.map.data.Element)1 LatLon (de.westnordost.osmapi.map.data.LatLon)1 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)1 HashMap (java.util.HashMap)1