Package org.openstreetmap.josm.data.osm

Examples of org.openstreetmap.josm.data.osm.Relation


        for (Way w1 : referers.getWays()) {
            assertTrue(w1.isIncomplete());
        }
        assertEquals(2, referers.getRelations().size())// two relations referring to w

        Relation r = lookupRelation(referers, 0);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        r = lookupRelation(referers, 1);
        assertFalse(r.isIncomplete());
    }
View Full Code Here


        assertEquals(expectedNodeIds.size(), referers.getNodes().size());
        for (Node n : referers.getNodes()) {
            assertTrue(expectedNodeIds.contains(n.getId()));
        }

        Relation r = lookupRelation(referers, 0);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        r = lookupRelation(referers, 1);
        assertFalse(r.isIncomplete());
    }
View Full Code Here

        assertFalse(r.isIncomplete());
    }

    @Test
    public void testBackreferenceForRelation() throws OsmTransferException {
        Relation r = lookupRelation(ds, 1);
        assertNotNull(r);
        // way with name "relation-1" is referred to by four relations:
        //    relation-6, relation-7, relation-8, relation-9
        //

        OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
        reader.setReadFull(false);
        DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
        printNumberOfPrimitives(referers);

        Set<Long> referringRelationsIds = new HashSet<>();
        Relation r6 = lookupRelation(referers, 6);
        assertNotNull(r6);
        assertFalse(r6.isIncomplete());
        referringRelationsIds.add(r6.getId());
        Relation r7 = lookupRelation(referers, 7);
        assertNotNull(r7);
        assertFalse(r7.isIncomplete());
        referringRelationsIds.add(r7.getId());
        Relation r8 = lookupRelation(referers, 8);
        assertNotNull(r8);
        assertFalse(r8.isIncomplete());
        referringRelationsIds.add(r8.getId());
        Relation r9 = lookupRelation(referers, 9);
        assertNotNull(r9);
        assertFalse(r9.isIncomplete());
        referringRelationsIds.add(r9.getId());

        for (Relation r1 : referers.getRelations()) {
            if (!referringRelationsIds.contains(r1.getId())) {
                assertTrue(r1.isIncomplete());
            }
View Full Code Here

        return ret;
    }

    @Test
    public void testBackreferenceForRelation_Full() throws OsmTransferException {
        Relation r = lookupRelation(ds, 1);
        assertNotNull(r);
        // way with name "relation-1" is referred to by four relations:
        //    relation-6, relation-7, relation-8, relation-9
        //

        OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
        reader.setReadFull(true);
        DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);

        Set<Long> referringRelationsIds = new HashSet<>();
        r = lookupRelation(referers, 6);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        referringRelationsIds.add(r.getId());
        r = lookupRelation(referers, 7);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        referringRelationsIds.add(r.getId());
        r = lookupRelation(referers, 8);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        referringRelationsIds.add(r.getId());
        r = lookupRelation(referers, 9);
        assertNotNull(r);
        assertFalse(r.isIncomplete());
        referringRelationsIds.add(r.getId());

        // all relations are fully loaded
        //
        for (Relation r1 : referers.getRelations()) {
            assertFalse(r1.isIncomplete());
        }

        // make sure we read all ways referred to by parent relations. These
        // ways are completely read after reading the relations
        //
        Set<Long> expectedWayIds = new HashSet<>();
        for (RelationMember m : lookupRelation(ds, 6).getMembers()) {
            if (m.isWay()) {
                expectedWayIds.add(m.getMember().getId());
            }
        }
        for (RelationMember m : lookupRelation(ds, 7).getMembers()) {
            if (m.isWay()) {
                expectedWayIds.add(m.getMember().getId());
            }
        }
        for (RelationMember m : lookupRelation(ds, 8).getMembers()) {
            if (m.isWay()) {
                expectedWayIds.add(m.getMember().getId());
            }
        }
        for (RelationMember m : lookupRelation(ds, 9).getMembers()) {
            if (m.isWay()) {
                expectedWayIds.add(m.getMember().getId());
            }
        }
        for (long id : expectedWayIds) {
            Way w = (Way) referers.getPrimitiveById(id, OsmPrimitiveType.WAY);
            assertNotNull(w);
            assertFalse(w.isIncomplete());
        }

        Set<Long> expectedNodeIds = new HashSet<>();
        for (int i = 6; i < 10; i++) {
            Relation r1 = lookupRelation(ds, i);
            expectedNodeIds.addAll(getNodeIdsInRelation(r1, true));
        }

        assertEquals(expectedNodeIds.size(), referers.getNodes().size());
        for (Node n : referers.getNodes()) {
View Full Code Here

    }

    @Test
    public void testOneRelationExistingMembersSelected() {
        DataSet source = new DataSet();
        Relation r1 = new Relation(1, 1);
        Node n20 = new Node(20, 1);
        n20.setCoor(new LatLon(0, 0));
        r1.addMember(new RelationMember("node-20",n20));
        Way w30 = new Way(30, 1);
        Node n21  = new Node(21);
        w30.addNode(n21);
        Node n22 = new Node(22);
        w30.addNode(n22);
        r1.addMember(new RelationMember("way-30",w30));
        Relation r40 = new Relation(40);
        r1.addMember(new RelationMember("relation-40", r40));
        source.addPrimitive(n20);
        source.addPrimitive(n21);
        source.addPrimitive(n22);
        source.addPrimitive(w30);
        source.addPrimitive(r40);
        source.addPrimitive(r1);
        source.setSelected(r1,n20,w30,r40);

        MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(source);
        DataSet hull = builder.build();
        assertNotNull(hull);
        assertEquals(1, hull.getWays().size());
        assertEquals(3, hull.getNodes().size());
        assertEquals(2, hull.getRelations().size());

        OsmPrimitive p = hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
        assertNotNull(p);
        assertEquals(p.getClass(), Relation.class);

        Way w = (Way)hull.getPrimitiveById(30,OsmPrimitiveType.WAY);
        assertNotNull(w);
        assertEquals(2, w.getNodesCount());
        Node n = (Node)hull.getPrimitiveById(21, OsmPrimitiveType.NODE);
        assertNotNull(n);
        assertTrue(w.containsNode(n));

        n = (Node)hull.getPrimitiveById(22,OsmPrimitiveType.NODE);
        assertNotNull(n);
        assertTrue(w.containsNode(n));

        Relation r = (Relation)hull.getPrimitiveById(40,OsmPrimitiveType.RELATION);
        assertNotNull(r);

        r = (Relation)hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
        assertNotNull(r);
        assertEquals(3, r.getMembersCount());
        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20,OsmPrimitiveType.NODE));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("way-30", hull.getPrimitiveById(30, OsmPrimitiveType.WAY));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("relation-40", hull.getPrimitiveById(40, OsmPrimitiveType.RELATION));
        assertTrue(r.getMembers().contains(m));
    }
View Full Code Here

    }

    @Test
    public void testOneRelationExistingMembersNotSelected() {
        DataSet source = new DataSet();
        Relation r1 = new Relation(1, 1);
        Node n20 = new Node(20);
        r1.addMember(new RelationMember("node-20",n20));
        Way w30 = new Way(30, 1);
        Node n21;
        w30.addNode(n21 = new Node(21));
        Node n22;
        w30.addNode(n22 = new Node(22));
        r1.addMember(new RelationMember("way-30",w30));
        Relation r40 = new Relation(40);
        r1.addMember(new RelationMember("relation-40", r40));
        source.addPrimitive(n20);
        source.addPrimitive(n21);
        source.addPrimitive(n22);
        source.addPrimitive(w30);
        source.addPrimitive(r40);
        source.addPrimitive(r1);
        source.setSelected(r1);

        MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(source);
        DataSet hull = builder.build();
        assertNotNull(hull);
        assertEquals(1, hull.getWays().size());
        assertEquals(1, hull.getNodes().size());
        assertEquals(2, hull.getRelations().size());

        OsmPrimitive p = hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
        assertNotNull(p);
        assertEquals(p.getClass(), Relation.class);

        Way w = (Way)hull.getPrimitiveById(30, OsmPrimitiveType.WAY);
        assertNotNull(w);
        assertTrue(w.isIncomplete());


        Node n = (Node)hull.getPrimitiveById(21,OsmPrimitiveType.NODE);
        assertNull(n);

        n = (Node)hull.getPrimitiveById(22, OsmPrimitiveType.NODE);
        assertNull(n);

        Relation r = (Relation)hull.getPrimitiveById(40, OsmPrimitiveType.RELATION);
        assertNotNull(r);
        assertTrue(r.isIncomplete());

        r = (Relation)hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
        assertNotNull(r);
        assertEquals(3, r.getMembersCount());
        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20, OsmPrimitiveType.NODE));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("way-30", hull.getPrimitiveById(30, OsmPrimitiveType.WAY));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("relation-40", hull.getPrimitiveById(40, OsmPrimitiveType.RELATION));
        assertTrue(r.getMembers().contains(m));
    }
View Full Code Here

    }

    @Test
    public void testOneRelationNewMembersNotSelected() {
        DataSet source = new DataSet();
        Relation r1 = new Relation();
        r1.put("name", "r1");
        Node n20 = new Node(new LatLon(20.0,20.0));
        n20.put("name", "n20");
        r1.addMember(new RelationMember("node-20",n20));

        Way w30 = new Way();
        w30.put("name", "w30");
        Node n21;
        w30.addNode(n21 = new Node(new LatLon(21.0,21.0)));
        n21.put("name","n21");
        Node n22;
        w30.addNode(n22 = new Node(new LatLon(22.0,22.0)));
        n22.put("name","n22");
        r1.addMember(new RelationMember("way-30",w30));
        Relation r40 = new Relation();
        r40.put("name", "r40");
        r1.addMember(new RelationMember("relation-40", r40));

        source.addPrimitive(n20);
        source.addPrimitive(n21);
        source.addPrimitive(n22);
        source.addPrimitive(w30);
        source.addPrimitive(r40);
        source.addPrimitive(r1);
        source.setSelected(r1);

        MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(source);
        DataSet hull = builder.build();
        assertNotNull(hull);
        assertEquals(1, hull.getWays().size());
        assertEquals(3, hull.getNodes().size());
        assertEquals(2, hull.getRelations().size());

        OsmPrimitive p = lookupByName(hull.getRelations(), "r1");
        assertNotNull(p);
        assertEquals(p.getClass(), Relation.class);

        Way w = (Way)lookupByName(hull.getWays(), "w30");
        assertNotNull(w);
        assertEquals(2, w.getNodesCount());

        Node n = (Node)lookupByName(hull.getNodes(), "n21");
        assertNotNull(n);
        assertTrue(w.containsNode(n));

        n = (Node)lookupByName(hull.getNodes(), "n22");
        assertNotNull(n);
        assertTrue(w.containsNode(n));

        Relation r = (Relation)lookupByName(hull.getRelations(), "r40");
        assertNotNull(r);

        r = (Relation)lookupByName(hull.getRelations(), "r1");
        assertNotNull(r);
        assertEquals(3, r.getMembersCount());
        RelationMember m = new RelationMember("node-20", lookupByName(hull.getNodes(), "n20"));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("way-30", lookupByName(hull.getWays(), "w30"));
        assertTrue(r.getMembers().contains(m));
        m = new RelationMember("relation-40", lookupByName(hull.getRelations(), "r40"));
        assertTrue(r.getMembers().contains(m));
    }
View Full Code Here

        // create a set of relations each with a random number of nodes,
        // and ways
        //
        for (int i=0; i< numRelations; i++) {
            Relation r = new Relation();
            r.put("name", "relation-" +i);
            int numNodesInRelation = (int)Math.round(Math.random() * 10);
            int start = (int)Math.round(Math.random() * numNodes);
            for (int j = 0; j < numNodesInRelation;j++) {
                int idx = (start + j) % 500;
                Node n = nodes.get(idx);
                r.addMember(new RelationMember("role-" + j, n));
            }
            int numWaysInRelation = (int)Math.round(Math.random() * 10);
            start = (int)Math.round(Math.random() * numWays);
            for (int j = 0; j < numWaysInRelation;j++) {
                int idx = (start + j) % 500;
                Way w = ways.get(idx);
                r.addMember(new RelationMember("role-" + j, w));
            }
            ds.addPrimitive(r);
        }

        return ds;
View Full Code Here

            reader.append(relations.get(i));
        }
        DataSet out = reader.parseOsm(NullProgressMonitor.INSTANCE);
        assertEquals(10, out.getRelations().size());
        for (Relation r1: out.getRelations()) {
            Relation r2 = (Relation)ds.getPrimitiveById(r1);
            assertNotNull(r2);
            assertEquals(r2.getMembersCount(), r1.getMembersCount());
            assertEquals(r2.get("name"),r2.get("name"));
        }
        assertTrue(reader.getMissingPrimitives().isEmpty());
    }
View Full Code Here

    }

    @Test
    public void testOneRelationExistingRecursive() {
        DataSet source = new DataSet();
        Relation r1 = new Relation(1, 1);
        r1.addMember(new RelationMember("relation-1",r1));
        source.addPrimitive(r1);
        source.setSelected(r1);

        MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(source);
        DataSet hull = builder.build();
        assertNotNull(hull);
        assertEquals(1, hull.getRelations().size());

        Relation r = (Relation)hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
        assertNotNull(r);
        assertEquals(1, r.getMembersCount());
        assertTrue(r.getMembers().contains(new RelationMember("relation-1",r)));
    }
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.data.osm.Relation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.