Search in sources :

Example 6 with EntityType

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));
    }
}
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 EntityType

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

Example 8 with EntityType

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;
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer)

Example 9 with EntityType

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

Example 10 with EntityType

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;
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean)

Aggregations

EntityType (org.openstreetmap.osmosis.core.domain.v0_6.EntityType)12 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)9 Test (org.junit.Test)5 EntityType (com.google.cloud.dialogflow.cx.v3beta1.EntityType)4 EntityType (org.hypertrace.entity.type.service.v1.EntityType)4 Test (org.junit.jupiter.api.Test)4 EntityType (com.google.cloud.dialogflow.v2.EntityType)3 ServiceException (com.google.protobuf.ServiceException)3 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)3 EntityType (org.hypertrace.entity.type.service.v2.EntityType)3 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Osmformat (crosby.binary.Osmformat)2 IOException (java.io.IOException)2 Document (org.hypertrace.core.documentstore.Document)2 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)2 BeforeClass (org.junit.BeforeClass)2 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)1 CreateEntityTypeRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest)1 CreateFlowRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest)1