use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.
the class OsmosisBinaryParser method parseRelations.
@Override
protected void parseRelations(List<Osmformat.Relation> rels) {
for (Osmformat.Relation i : rels) {
List<Tag> tags = new ArrayList<Tag>();
for (int j = 0; j < i.getKeysCount(); j++) {
tags.add(new Tag(getStringById(i.getKeys(j)), getStringById(i.getVals(j))));
}
long id = i.getId();
long lastMid = 0;
List<RelationMember> nodes = new ArrayList<RelationMember>();
for (int j = 0; j < i.getMemidsCount(); j++) {
long mid = lastMid + i.getMemids(j);
lastMid = mid;
String role = getStringById(i.getRolesSid(j));
EntityType etype = null;
if (i.getTypes(j) == Osmformat.Relation.MemberType.NODE) {
etype = EntityType.Node;
} else if (i.getTypes(j) == Osmformat.Relation.MemberType.WAY) {
etype = EntityType.Way;
} else if (i.getTypes(j) == Osmformat.Relation.MemberType.RELATION) {
etype = EntityType.Relation;
} else {
// TODO; Illegal file?
assert false;
}
nodes.add(new RelationMember(mid, etype, role));
}
// long id, int version, TimestampContainer timestampContainer,
// OsmUser user,
// long changesetId, Collection<Tag> tags,
// List<RelationMember> members
Relation tmp;
if (i.hasInfo()) {
Osmformat.Info info = i.getInfo();
tmp = new Relation(new CommonEntityData(id, info.getVersion(), getDate(info), getUser(info), info.getChangeset(), tags), nodes);
} else {
tmp = new Relation(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE, NOCHANGESET, tags), nodes);
}
sink.process(new RelationContainer(tmp));
}
}
use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer 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.container.v0_6.RelationContainer in project osmosis by openstreetmap.
the class AreaFilter method selectChildNonRelationsPass.
/**
* Select all relation members of type node or way for existing selected relations.
*/
private void selectChildNonRelationsPass() {
try (ReleasableIterator<RelationContainer> i = allRelations.iterate()) {
while (i.hasNext()) {
Relation relation = i.next().getEntity();
long relationId = relation.getId();
// Only examine available relations.
if (availableRelations.get(relationId)) {
// Select the member if it hasn't already been selected.
for (RelationMember member : relation.getMembers()) {
switch(member.getMemberType()) {
case Node:
availableNodes.set(member.getMemberId());
break;
case Way:
availableWays.set(member.getMemberId());
break;
default:
break;
}
}
}
}
}
}
use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.
the class AreaFilter method selectParentRelationsPass.
private boolean selectParentRelationsPass() {
try (ReleasableIterator<RelationContainer> i = allRelations.iterate()) {
int selectionCount;
selectionCount = 0;
while (i.hasNext()) {
Relation relation = i.next().getEntity();
long relationId = relation.getId();
// Ignore relations that have already been selected.
if (!availableRelations.get(relationId)) {
// relations is also available.
for (RelationMember member : relation.getMembers()) {
if (member.getMemberType().equals(EntityType.Relation)) {
if (availableRelations.get(member.getMemberId())) {
availableRelations.set(relationId);
selectionCount++;
}
}
}
}
}
return selectionCount > 0;
}
}
use of org.openstreetmap.osmosis.core.container.v0_6.RelationContainer in project osmosis by openstreetmap.
the class PostgreSqlDatasetContext method iterate.
/**
* {@inheritDoc}
*/
@Override
public ReleasableIterator<EntityContainer> iterate() {
List<Bound> bounds;
List<ReleasableIterator<EntityContainer>> sources;
if (!initialized) {
initialize();
}
// Build the bounds list.
bounds = new ArrayList<Bound>();
bounds.add(new Bound("Osmosis " + OsmosisConstants.VERSION));
sources = new ArrayList<ReleasableIterator<EntityContainer>>();
sources.add(new UpcastIterator<EntityContainer, BoundContainer>(new BoundContainerIterator(new ReleasableAdaptorForIterator<Bound>(bounds.iterator()))));
sources.add(new UpcastIterator<EntityContainer, NodeContainer>(new NodeContainerIterator(nodeDao.iterate())));
sources.add(new UpcastIterator<EntityContainer, WayContainer>(new WayContainerIterator(wayDao.iterate())));
sources.add(new UpcastIterator<EntityContainer, RelationContainer>(new RelationContainerIterator(relationDao.iterate())));
return new MultipleSourceIterator<EntityContainer>(sources);
}
Aggregations