Search in sources :

Example 1 with RelationContainer

use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.

the class EntityReporter method process.

/**
 * {@inheritDoc}
 */
public void process(EntityContainer entityContainer) {
    String userName;
    final UserStatistics user;
    // Obtain the user statistics object.
    userName = entityContainer.getEntity().getUser().getName();
    if (userName != null && userName.length() > 0) {
        if (userMap.containsKey(userName)) {
            user = userMap.get(userName);
        } else {
            user = new UserStatistics(userName);
            userMap.put(userName, user);
        }
    } else {
        user = anonymousUser;
    }
    // Increment the relevant user statistic.
    entityContainer.process(new EntityProcessor() {

        private UserStatistics processorUser = user;

        public void process(BoundContainer bound) {
        // Do nothing.
        }

        public void process(NodeContainer node) {
            processorUser.incrementNodeCount();
            totalUser.incrementNodeCount();
        }

        public void process(WayContainer way) {
            processorUser.incrementWayCount();
            totalUser.incrementWayCount();
        }

        public void process(RelationContainer relation) {
            processorUser.incrementRelationCount();
            totalUser.incrementRelationCount();
        }
    });
}
Also used : WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) EntityProcessor(org.openstreetmap.osmosis.core.container.v0_6.EntityProcessor)

Example 2 with RelationContainer

use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.

the class OsmWriterTest method testProcess8.

/**
 * Test processing a Relation.
 */
@Test
public final void testProcess8() {
    Relation testRelation;
    testRelation = new Relation(new CommonEntityData(3456, 0, new Date(), new OsmUser(12, "OsmosisTest"), 0));
    testRelation.getMembers().add(new RelationMember(1234, EntityType.Node, "role1"));
    testRelation.getTags().add(new Tag("test_key1", "test_value1"));
    testOsmWriter.process(new RelationContainer(testRelation));
// Nothing to assert; just expect no exception
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Date(java.util.Date) Test(org.junit.Test)

Example 3 with RelationContainer

use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.

the class OsmWriterTest method testProcess9.

/**
 * Test processing a Bound after a Relation.
 */
@Test(expected = OsmosisRuntimeException.class)
public final void testProcess9() {
    Relation testRelation;
    testRelation = new Relation(new CommonEntityData(3456, 0, new Date(), new OsmUser(12, "OsmosisTest"), 0));
    testRelation.getMembers().add(new RelationMember(1234, EntityType.Node, "role1"));
    testRelation.getTags().add(new Tag("test_key1", "test_value1"));
    testOsmWriter.process(new RelationContainer(testRelation));
    testOsmWriter.process(new BoundContainer(new Bound("source")));
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Date(java.util.Date) Test(org.junit.Test)

Example 4 with RelationContainer

use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.

the class FastXmlParser method readOsm.

/**
 * Parses the xml and sends all data to the sink.
 */
public void readOsm() {
    try {
        String generator = null;
        if (reader.nextTag() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("osm")) {
            String fileVersion;
            fileVersion = reader.getAttributeValue(null, ATTRIBUTE_NAME_VERSION);
            if (!XmlConstants.OSM_VERSION.equals(fileVersion)) {
                LOG.warning("Expected version " + XmlConstants.OSM_VERSION + " but received " + fileVersion + ".");
            }
            generator = reader.getAttributeValue(null, ATTRIBUTE_NAME_GENERATOR);
            reader.nextTag();
            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(ELEMENT_NAME_BOUND)) {
                LOG.fine("Legacy <bound> element encountered.");
                sink.process(new BoundContainer(readBound()));
            }
            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(ELEMENT_NAME_BOUNDS)) {
                sink.process(new BoundContainer(readBounds(generator)));
            }
            while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                // Node, way, relation
                if (reader.getLocalName().equals(ELEMENT_NAME_NODE)) {
                    sink.process(new NodeContainer(readNode()));
                } else if (reader.getLocalName().equals(ELEMENT_NAME_WAY)) {
                    sink.process(new WayContainer(readWay()));
                } else if (reader.getLocalName().equals(ELEMENT_NAME_RELATION)) {
                    sink.process(new RelationContainer(readRelation()));
                } else {
                    readUnknownElement();
                }
            }
        } else {
            throw new XMLStreamException();
        }
    } catch (Exception e) {
        throw new OsmosisRuntimeException(e);
    }
}
Also used : WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) XMLStreamException(javax.xml.stream.XMLStreamException) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) XMLStreamException(javax.xml.stream.XMLStreamException) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 5 with RelationContainer

use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.

the class UsedNodeFilter method complete.

/**
 * {@inheritDoc}
 */
public void complete() {
    // send on all required nodes
    ReleasableIterator<NodeContainer> nodeIterator = allNodes.iterate();
    while (nodeIterator.hasNext()) {
        NodeContainer nodeContainer = nodeIterator.next();
        long nodeId = nodeContainer.getEntity().getId();
        if (!requiredNodes.get(nodeId)) {
            continue;
        }
        sink.process(nodeContainer);
    }
    nodeIterator.close();
    nodeIterator = null;
    // send on all ways
    ReleasableIterator<WayContainer> wayIterator = allWays.iterate();
    while (wayIterator.hasNext()) {
        sink.process(wayIterator.next());
    }
    wayIterator.close();
    wayIterator = null;
    // send on all relations
    ReleasableIterator<RelationContainer> relationIterator = allRelations.iterate();
    while (relationIterator.hasNext()) {
        sink.process(relationIterator.next());
    }
    relationIterator.close();
    relationIterator = null;
    // done
    sink.complete();
}
Also used : WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)

Aggregations

RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)10 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)10 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)9 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)8 BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)7 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)5 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)5 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)5 BoundContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator)4 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)4 NodeContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.NodeContainerIterator)4 RelationContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.RelationContainerIterator)4 WayContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.WayContainerIterator)4 ReleasableIterator (org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator)4 MultipleSourceIterator (org.openstreetmap.osmosis.core.store.MultipleSourceIterator)4 Date (java.util.Date)3 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)3 Osmformat (crosby.binary.Osmformat)2 ArrayList (java.util.ArrayList)2