Search in sources :

Example 11 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class MergeBoundTest method testOneSourceEmpty.

/**
 * Tests the proper working of the merge task if exactly one source is
 * empty with respect to the declared bound.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testOneSourceEmpty() throws Exception {
    RunnableSource source0 = new EmptyReader();
    Bound bound1 = new Bound(5, 6, 8, 7, "source2");
    RunnableSource source1 = new BoundSource(bound1, true);
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
    List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
    Assert.assertEquals(2, mergedList.size());
    Assert.assertEquals(bound1, mergedList.get(0).getEntity());
    Assert.assertEquals(EntityType.Node, mergedList.get(1).getEntity().getType());
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) EmptyReader(org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader) Test(org.junit.Test)

Example 12 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class MergeBoundTest method testSource1HasBound.

/**
 * Tests whether merge will delete the declared bound if only source 1
 * has a declared bound.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSource1HasBound() throws Exception {
    RunnableSource source0 = new BoundSource(new Bound(1, 2, 4, 3, "source0"), false);
    RunnableSource source1 = new BoundSource(new Bound(5, 6, 8, 7, "source1"), true);
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
    List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
    Assert.assertEquals(2, mergedList.size());
    for (EntityContainer entityContainer : mergedList) {
        Assert.assertEquals(EntityType.Node, entityContainer.getEntity().getType());
    }
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) Test(org.junit.Test)

Example 13 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class PbfBlobDecoder method processNodes.

private void processNodes(Osmformat.DenseNodes nodes, PbfFieldDecoder fieldDecoder) {
    List<Long> idList = nodes.getIdList();
    List<Long> latList = nodes.getLatList();
    List<Long> lonList = nodes.getLonList();
    // Ensure parallel lists are of equal size.
    if ((idList.size() != latList.size()) || (idList.size() != lonList.size())) {
        throw new OsmosisRuntimeException("Number of ids (" + idList.size() + "), latitudes (" + latList.size() + "), and longitudes (" + lonList.size() + ") don't match");
    }
    Iterator<Integer> keysValuesIterator = nodes.getKeysValsList().iterator();
    Osmformat.DenseInfo denseInfo;
    if (nodes.hasDenseinfo()) {
        denseInfo = nodes.getDenseinfo();
    } else {
        denseInfo = null;
    }
    long nodeId = 0;
    long latitude = 0;
    long longitude = 0;
    int userId = 0;
    int userSid = 0;
    long timestamp = 0;
    long changesetId = 0;
    for (int i = 0; i < idList.size(); i++) {
        CommonEntityData entityData;
        org.openstreetmap.osmosis.core.domain.v0_6.Node node;
        // Delta decode node fields.
        nodeId += idList.get(i);
        latitude += latList.get(i);
        longitude += lonList.get(i);
        if (denseInfo != null) {
            // Delta decode dense info fields.
            userId += denseInfo.getUid(i);
            userSid += denseInfo.getUserSid(i);
            timestamp += denseInfo.getTimestamp(i);
            changesetId += denseInfo.getChangeset(i);
            // Build the user, but only if one exists.
            OsmUser user;
            if (userId >= 0) {
                user = new OsmUser(userId, fieldDecoder.decodeString(userSid));
            } else {
                user = OsmUser.NONE;
            }
            entityData = new CommonEntityData(nodeId, denseInfo.getVersion(i), fieldDecoder.decodeTimestamp(timestamp), user, changesetId);
        } else {
            entityData = new CommonEntityData(nodeId, EMPTY_VERSION, EMPTY_TIMESTAMP, OsmUser.NONE, EMPTY_CHANGESET);
        }
        // Build the tags. The key and value string indexes are sequential
        // in the same PBF array. Each set of tags is delimited by an index
        // with a value of 0.
        Collection<Tag> tags = entityData.getTags();
        while (keysValuesIterator.hasNext()) {
            int keyIndex = keysValuesIterator.next();
            if (keyIndex == 0) {
                break;
            }
            if (!keysValuesIterator.hasNext()) {
                throw new OsmosisRuntimeException("The PBF DenseInfo keys/values list contains a key with no corresponding value.");
            }
            int valueIndex = keysValuesIterator.next();
            Tag tag = new Tag(fieldDecoder.decodeString(keyIndex), fieldDecoder.decodeString(valueIndex));
            tags.add(tag);
        }
        node = new org.openstreetmap.osmosis.core.domain.v0_6.Node(entityData, fieldDecoder.decodeLatitude(latitude), fieldDecoder.decodeLongitude(longitude));
        // Add the bound object to the results.
        decodedEntities.add(new NodeContainer(node));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Osmformat(crosby.binary.Osmformat) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 14 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class PbfBlobDecoder method processRelations.

private void processRelations(List<Osmformat.Relation> relations, PbfFieldDecoder fieldDecoder) {
    for (Osmformat.Relation relation : relations) {
        org.openstreetmap.osmosis.core.domain.v0_6.Relation osmRelation;
        CommonEntityData entityData;
        if (relation.hasInfo()) {
            entityData = buildCommonEntityData(relation.getId(), relation.getKeysList(), relation.getValsList(), relation.getInfo(), fieldDecoder);
        } else {
            entityData = buildCommonEntityData(relation.getId(), relation.getKeysList(), relation.getValsList(), fieldDecoder);
        }
        osmRelation = new org.openstreetmap.osmosis.core.domain.v0_6.Relation(entityData);
        buildRelationMembers(osmRelation, relation.getMemidsList(), relation.getRolesSidList(), relation.getTypesList(), fieldDecoder);
        // Add the bound object to the results.
        decodedEntities.add(new RelationContainer(osmRelation));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) Osmformat(crosby.binary.Osmformat)

Example 15 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class BoundSetterTest method setNewBoundTest.

/**
 * Tests the bound setting when there is no bound upstream.
 */
@Test
public void setNewBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    Bound newBound = new Bound(2, 1, 4, 3, "NewBound");
    BoundSetter setter = new BoundSetter(newBound);
    setter.setSink(inspector);
    setter.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    setter.complete();
    setter.close();
    EntityContainer ec = inspector.getProcessedEntities().iterator().next();
    Assert.assertEquals(EntityType.Bound, ec.getEntity().getType());
    Bound bound = (Bound) ec.getEntity();
    Assert.assertEquals(bound, newBound);
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)46 Test (org.junit.Test)25 BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)22 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)19 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)14 SinkEntityInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector)14 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)13 Date (java.util.Date)11 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)11 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)7 RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)6 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)6 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)5 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)5 RunnableSource (org.openstreetmap.osmosis.core.task.v0_6.RunnableSource)5 Osmformat (crosby.binary.Osmformat)4 BoundContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator)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