Search in sources :

Example 6 with RelationContainer

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));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) ArrayList(java.util.ArrayList) Osmformat(crosby.binary.Osmformat) EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 7 with RelationContainer

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));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) Osmformat(crosby.binary.Osmformat)

Example 8 with RelationContainer

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;
                    }
                }
            }
        }
    }
}
Also used : RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 9 with RelationContainer

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;
    }
}
Also used : RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 10 with RelationContainer

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);
}
Also used : NodeContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.NodeContainerIterator) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) MultipleSourceIterator(org.openstreetmap.osmosis.core.store.MultipleSourceIterator) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) RelationContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.RelationContainerIterator) ReleasableIterator(org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) WayContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.WayContainerIterator) BoundContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)

Aggregations

RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)10 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)10 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)9 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)8 BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)7 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)5 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)5 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)5 BoundContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator)4 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)4 NodeContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.NodeContainerIterator)4 RelationContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.RelationContainerIterator)4 WayContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.WayContainerIterator)4 ReleasableIterator (org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator)4 MultipleSourceIterator (org.openstreetmap.osmosis.core.store.MultipleSourceIterator)4 Date (java.util.Date)3 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)3 Osmformat (crosby.binary.Osmformat)2 ArrayList (java.util.ArrayList)2