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());
}
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());
}
}
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));
}
}
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));
}
}
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);
}
Aggregations