Search in sources :

Example 6 with OsmRelationMember

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);
        }
    }
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 7 with OsmRelationMember

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);
}
Also used : Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) RelationMember(de.topobyte.osm4j.core.model.impl.RelationMember) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 8 with OsmRelationMember

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);
}
Also used : OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 9 with OsmRelationMember

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();
}
Also used : PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup) EntityType(de.topobyte.osm4j.core.model.iface.EntityType) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Aggregations

OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)9 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)8 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)3 TLongSet (com.slimjars.dist.gnu.trove.set.TLongSet)3 TLongHashSet (com.slimjars.dist.gnu.trove.set.hash.TLongHashSet)3 Relation (de.topobyte.osm4j.core.model.impl.Relation)3 ArrayList (java.util.ArrayList)3 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)2 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)2 Node (de.topobyte.osm4j.core.model.impl.Node)2 Way (de.topobyte.osm4j.core.model.impl.Way)2 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)1 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)1 RelationMember (de.topobyte.osm4j.core.model.impl.RelationMember)1 PrimitiveGroup (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)1