use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.
the class EntityFinderThrowMissing method findMemberRelationsRecursively.
private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) throws EntityNotFoundException {
TLongSet ids = new TLongHashSet();
while (!queue.isEmpty()) {
OsmRelation relation = queue.remove();
for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
if (member.getType() != EntityType.Relation) {
continue;
}
long id = member.getId();
if (ids.contains(id)) {
continue;
}
ids.add(id);
OsmRelation child = entityProvider.getRelation(id);
outRelations.add(child);
queue.add(child);
}
}
}
use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.
the class ImplUtil method clone.
public static Relation clone(OsmRelation relation) {
List<? extends OsmTag> tags = cloneTags(relation);
OsmMetadata metadata = cloneMetadata(relation);
List<RelationMember> members = new ArrayList<>(relation.getNumberOfMembers());
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
OsmRelationMember member = relation.getMember(i);
members.add(new RelationMember(member.getId(), member.getType(), member.getRole()));
}
return new Relation(relation.getId(), members, tags, metadata);
}
use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.
the class EqualityUtil method equals.
public static boolean equals(OsmRelation a, OsmRelation b) {
if (a.getId() != b.getId()) {
return false;
}
int n = a.getNumberOfMembers();
if (n != b.getNumberOfMembers()) {
return false;
}
for (int i = 0; i < n; i++) {
OsmRelationMember mA = a.getMember(i);
OsmRelationMember mB = b.getMember(i);
if (mA.getId() != mB.getId() || mA.getType() != mB.getType() || !mA.getRole().equals(mB.getRole())) {
return false;
}
}
Map<String, String> tagsA = OsmModelUtil.getTagsAsMap(a);
Map<String, String> tagsB = OsmModelUtil.getTagsAsMap(b);
return tagsA.equals(tagsB);
}
use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-pbf by topobyte.
the class PbfWriter method serializeRelations.
private Osmformat.PrimitiveGroup serializeRelations(Collection<OsmRelation> relations) {
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
for (OsmRelation relation : relations) {
Osmformat.Relation.Builder bi = Osmformat.Relation.newBuilder();
bi.setId(relation.getId());
long lastid = 0;
for (int k = 0; k < relation.getNumberOfMembers(); k++) {
OsmRelationMember j = relation.getMember(k);
long id = j.getId();
bi.addMemids(id - lastid);
lastid = id;
EntityType t = j.getType();
Osmformat.Relation.MemberType type = getType(t);
bi.addTypes(type);
bi.addRolesSid(stringTable.getIndex(j.getRole()));
}
for (int k = 0; k < relation.getNumberOfTags(); k++) {
OsmTag t = relation.getTag(k);
bi.addKeys(stringTable.getIndex(t.getKey()));
bi.addVals(stringTable.getIndex(t.getValue()));
}
if (writeMetadata && relation.getMetadata() != null) {
bi.setInfo(serializeMetadata(relation));
}
builder.addRelations(bi);
}
return builder.build();
}
Aggregations