use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType 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.domain.v0_6.EntityType in project osmosis by openstreetmap.
the class ChangeSimplifierImpl method process.
/**
* {@inheritDoc}
*/
@Override
public void process(ChangeContainer change) {
// then we must process the current changes.
if (currentChanges.size() > 0) {
long currentId;
EntityType currentEntityType;
currentId = currentChanges.get(0).getEntityContainer().getEntity().getId();
currentEntityType = currentChanges.get(0).getEntityContainer().getEntity().getType();
if (currentId != change.getEntityContainer().getEntity().getId() || currentEntityType != change.getEntityContainer().getEntity().getType()) {
flushCurrentChanges();
}
}
currentChanges.add(change);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.
the class EntityHistoryListReader method next.
/**
* {@inheritDoc}
*/
@Override
public List<ChangeContainer> next() {
List<ChangeContainer> changeList;
Entity peekEntity;
long currentId;
EntityType currentEntityType;
// Get the next change from the underlying stream.
peekEntity = sourceIterator.peekNext().getEntityContainer().getEntity();
currentId = peekEntity.getId();
currentEntityType = peekEntity.getType();
// Loop until all history values for the current element are exhausted.
changeList = new ArrayList<ChangeContainer>();
while (sourceIterator.hasNext()) {
ChangeContainer tmpChangeContainer = sourceIterator.peekNext();
// Break out of the loop when we reach the next entity in the stream.
if (currentId != tmpChangeContainer.getEntityContainer().getEntity().getId() || !currentEntityType.equals(tmpChangeContainer.getEntityContainer().getEntity().getType())) {
break;
}
// We want the value that we have already peeked from the iterator, so remove it from the iterator.
sourceIterator.next();
// Add the change to the result list.
changeList.add(tmpChangeContainer);
}
return changeList;
}
use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project atlas by osmlab.
the class OsmPbfCounter method markRelationAndMembersInsideBoundary.
private void markRelationAndMembersInsideBoundary(final Relation relation) {
// Add all the members
for (final RelationMember member : relation.getMembers()) {
final EntityType memberType = member.getMemberType();
final Long memberIdentifier = member.getMemberId();
if (memberType == EntityType.Node) {
this.nodeIdentifiersToInclude.add(memberIdentifier);
} else if (memberType == EntityType.Way) {
this.wayIdentifiersToInclude.add(memberIdentifier);
// If this line was originally excluded, bring it in now
final Way toAdd = this.waysToExclude.get(memberIdentifier);
if (toAdd != null) {
addWayNodes(this.nodeIdentifiersBroughtInByWaysOrRelations, toAdd);
this.waysToExclude.remove(memberIdentifier, toAdd);
}
} else if (memberType == EntityType.Relation) {
this.relationIdentifiersToInclude.add(member.getMemberId());
}
}
// Add the relation itself
this.relationIdentifiersToInclude.add(relation.getId());
}
use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project atlas by osmlab.
the class OsmPbfReader method constructRelationBean.
/**
* Creates a {@link RelationBean} for the given {@link Relation}. Note: The returned bean can be
* empty.
*
* @param relation
* The {@link Relation} for which to create the {@link RelationBean}
* @return the created {@link RelationBean}
*/
private RelationBean constructRelationBean(final Relation relation) {
final RelationBean bean = new RelationBean();
for (final RelationMember member : relation.getMembers()) {
final long memberIdentifier = padIdentifier(member.getMemberId());
final EntityType memberType = member.getMemberType();
final String role = member.getMemberRole();
if (memberType == EntityType.Node) {
if (this.builder.peek().point(memberIdentifier) != null) {
bean.addItem(memberIdentifier, role, ItemType.POINT);
} else {
logger.trace(MISSING_MEMBER_MESSAGE, relation.getId(), EntityType.Node, memberIdentifier);
}
} else if (memberType == EntityType.Way) {
if (this.builder.peek().line(memberIdentifier) != null) {
bean.addItem(memberIdentifier, role, ItemType.LINE);
} else {
logger.trace(MISSING_MEMBER_MESSAGE, relation.getId(), EntityType.Way, memberIdentifier);
}
} else if (memberType == EntityType.Relation) {
if (this.builder.peek().relation(memberIdentifier) != null) {
bean.addItem(memberIdentifier, role, ItemType.RELATION);
} else {
logger.trace(MISSING_MEMBER_MESSAGE, relation.getId(), EntityType.Relation, memberIdentifier);
}
} else {
// A Bound should never be a Relation member; if this is the case, log and continue
logger.error("Invalid Bound member {} found for Relation {}", member.getMemberId(), relation.getId());
}
}
return bean;
}
Aggregations