Search in sources :

Example 1 with OsmRelationMember

use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-pbf by topobyte.

the class PbfWriter method addMemberRolesToStringTable.

private void addMemberRolesToStringTable(Collection<OsmRelation> relations) {
    for (OsmRelation relation : relations) {
        for (int k = 0; k < relation.getNumberOfMembers(); k++) {
            OsmRelationMember j = relation.getMember(k);
            stringTable.incr(j.getRole());
        }
    }
}
Also used : OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 2 with OsmRelationMember

use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.

the class ListDataSetLoader method read.

public static InMemoryListDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    InMemoryListDataSet dataSet = new InMemoryListDataSet();
    List<OsmNode> nodes = dataSet.getNodes();
    List<OsmWay> ways = dataSet.getWays();
    List<OsmRelation> relations = dataSet.getRelations();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                OsmNode node = (OsmNode) container.getEntity();
                if (!keepNodeTags) {
                    node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
                }
                nodes.add(node);
                break;
            case Way:
                OsmWay way = (OsmWay) container.getEntity();
                if (!keepWayTags) {
                    TLongArrayList ids = new TLongArrayList();
                    for (int i = 0; i < way.getNumberOfNodes(); i++) {
                        ids.add(way.getNodeId(i));
                    }
                    way = new Way(way.getId(), ids);
                }
                ways.add(way);
                break;
            case Relation:
                OsmRelation relation = (OsmRelation) container.getEntity();
                if (!keepRelationTags) {
                    List<OsmRelationMember> members = new ArrayList<>();
                    for (int i = 0; i < relation.getNumberOfMembers(); i++) {
                        members.add(relation.getMember(i));
                    }
                    relation = new Relation(relation.getId(), members);
                }
                relations.add(relation);
                break;
        }
    }
    return dataSet;
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 3 with OsmRelationMember

use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.

the class MapDataSetLoader method read.

public static InMemoryMapDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
    TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
    TLongObjectMap<OsmWay> ways = dataSet.getWays();
    TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                OsmNode node = (OsmNode) container.getEntity();
                if (!keepNodeTags) {
                    node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
                }
                nodes.put(node.getId(), node);
                break;
            case Way:
                OsmWay way = (OsmWay) container.getEntity();
                if (!keepWayTags) {
                    TLongArrayList ids = new TLongArrayList();
                    for (int i = 0; i < way.getNumberOfNodes(); i++) {
                        ids.add(way.getNodeId(i));
                    }
                    way = new Way(way.getId(), ids);
                }
                ways.put(way.getId(), way);
                break;
            case Relation:
                OsmRelation relation = (OsmRelation) container.getEntity();
                if (!keepRelationTags) {
                    List<OsmRelationMember> members = new ArrayList<>();
                    for (int i = 0; i < relation.getNumberOfMembers(); i++) {
                        members.add(relation.getMember(i));
                    }
                    relation = new Relation(relation.getId(), members);
                }
                relations.put(relation.getId(), relation);
                break;
        }
    }
    return dataSet;
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 4 with OsmRelationMember

use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.

the class EntityFinderIgnoreMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) {
    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);
            try {
                OsmRelation child = entityProvider.getRelation(id);
                outRelations.add(child);
                queue.add(child);
            } catch (EntityNotFoundException e) {
            // ignore silently
            }
        }
    }
}
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 5 with OsmRelationMember

use of de.topobyte.osm4j.core.model.iface.OsmRelationMember in project osm4j-core by topobyte.

the class EntityFinderLogMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) {
    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);
            try {
                OsmRelation child = entityProvider.getRelation(id);
                outRelations.add(child);
                queue.add(child);
            } catch (EntityNotFoundException e) {
                logRelationNotFound(id);
            }
        }
    }
}
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)

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