Search in sources :

Example 16 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class PbfBlobDecoder method buildRelationMembers.

private void buildRelationMembers(org.openstreetmap.osmosis.core.domain.v0_6.Relation relation, List<Long> memberIds, List<Integer> memberRoles, List<Osmformat.Relation.MemberType> memberTypes, PbfFieldDecoder fieldDecoder) {
    List<RelationMember> members = relation.getMembers();
    // Ensure parallel lists are of equal size.
    if ((memberIds.size() != memberRoles.size()) || (memberIds.size() != memberTypes.size())) {
        throw new OsmosisRuntimeException("Number of member ids (" + memberIds.size() + "), member roles (" + memberRoles.size() + "), and member types (" + memberTypes.size() + ") don't match");
    }
    Iterator<Long> memberIdIterator = memberIds.iterator();
    Iterator<Integer> memberRoleIterator = memberRoles.iterator();
    Iterator<Osmformat.Relation.MemberType> memberTypeIterator = memberTypes.iterator();
    // Build up the list of relation members for the way. The member ids are
    // delta encoded meaning that each id is stored as a delta against
    // the previous one.
    long memberId = 0;
    while (memberIdIterator.hasNext()) {
        Osmformat.Relation.MemberType memberType = memberTypeIterator.next();
        memberId += memberIdIterator.next();
        EntityType entityType;
        RelationMember member;
        if (memberType == Osmformat.Relation.MemberType.NODE) {
            entityType = EntityType.Node;
        } else if (memberType == Osmformat.Relation.MemberType.WAY) {
            entityType = EntityType.Way;
        } else if (memberType == Osmformat.Relation.MemberType.RELATION) {
            entityType = EntityType.Relation;
        } else {
            throw new OsmosisRuntimeException("Member type of " + memberType + " is not supported.");
        }
        member = new RelationMember(memberId, entityType, fieldDecoder.decodeString(memberRoleIterator.next()));
        members.add(member);
    }
}
Also used : Osmformat(crosby.binary.Osmformat) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 17 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class IntegrityReporter method process.

/**
 * {@inheritDoc}
 */
public void process(RelationContainer relationContainer) {
    Relation relation;
    relation = relationContainer.getEntity();
    for (RelationMember relationMember : relation.getMembers()) {
        EntityType memberType;
        memberType = relationMember.getMemberType();
        if (EntityType.Node.equals(memberType)) {
            if (!nodeBitSet.get(relationMember.getMemberId())) {
                initialize();
                write("Relation," + relation.getId() + ",Node," + relationMember.getMemberId());
                writeNewLine();
            }
        } else if (EntityType.Way.equals(memberType)) {
            if (!wayBitSet.get(relationMember.getMemberId())) {
                initialize();
                write("Relation," + relation.getId() + ",Way," + relationMember.getMemberId());
                writeNewLine();
            }
        }
    }
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 18 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class RelationMemberRowMapper method processRow.

/**
 * {@inheritDoc}
 */
@Override
public void processRow(ResultSet resultSet) throws SQLException {
    long memberId;
    EntityType memberType;
    String memberRole;
    RelationMember relationMember;
    memberId = resultSet.getLong("member_id");
    memberType = memberTypeParser.parse(resultSet.getString("member_type"));
    memberRole = resultSet.getString("member_role");
    relationMember = new RelationMember(memberId, memberType, memberRole);
    listener.process(relationMember, resultSet);
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 19 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class AreaFilter method emitRelation.

/**
 * Sends a relation to the sink. This will perform any necessary transformations on the way before
 * sending it.
 *
 * @param relationContainer
 *            Relation to be sent.
 */
private void emitRelation(RelationContainer relationContainer) {
    if (clipIncompleteEntities) {
        RelationContainer filteredRelationContainer;
        Relation filteredRelation;
        filteredRelationContainer = relationContainer.getWriteableInstance();
        filteredRelation = filteredRelationContainer.getEntity();
        // Remove members for entities that are unavailable.
        for (Iterator<RelationMember> i = filteredRelation.getMembers().iterator(); i.hasNext(); ) {
            RelationMember member = i.next();
            EntityType memberType;
            long memberId;
            memberType = member.getMemberType();
            memberId = member.getMemberId();
            switch(memberType) {
                case Node:
                    if (!availableNodes.get(memberId)) {
                        i.remove();
                    }
                    break;
                case Way:
                    if (!availableWays.get(memberId)) {
                        i.remove();
                    }
                    break;
                case Relation:
                    if (!availableRelations.get(memberId)) {
                        i.remove();
                    }
                    break;
                default:
                    break;
            }
        }
        // Only add relations that contain entities.
        if (filteredRelation.getMembers().size() > 0) {
            sink.process(filteredRelationContainer);
        }
    } else {
        sink.process(relationContainer);
    }
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) 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 20 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class TransformHelper method processEntityContainer.

/**
 * Transforms entity container according to configFile.
 *
 * @param entityContainer
 *            The entity to be processed.
 * @return transformed (if needed) entityContainer
 */
protected EntityContainer processEntityContainer(EntityContainer entityContainer) {
    // Entities may have been made read-only at some point in the pipeline.
    // We want a writeable instance so that we can update the tags.
    EntityContainer writeableEntityContainer = entityContainer.getWriteableInstance();
    Entity entity = entityContainer.getEntity();
    Collection<Tag> entityTags = entity.getTags();
    EntityType entityType = entity.getType();
    // Store the tags in a map keyed by tag key.
    Map<String, String> tagMap = new HashMap<String, String>();
    for (Tag tag : entity.getTags()) {
        tagMap.put(tag.getKey(), tag.getValue());
    }
    // Apply tag transformations.
    for (Translation translation : translations) {
        Collection<Match> matches = translation.match(tagMap, TTEntityType.fromEntityType06(entityType), entity.getUser().getName(), entity.getUser().getId());
        if (matches == null || matches.isEmpty()) {
            continue;
        }
        if (translation.isDropOnMatch()) {
            return null;
        }
        Map<String, String> newTags = new HashMap<String, String>();
        for (Output output : translation.getOutputs()) {
            output.apply(tagMap, newTags, matches, translation.getDataSources());
        }
        tagMap = newTags;
    }
    // Replace the entity tags with the transformed values.
    entityTags.clear();
    for (Entry<String, String> tag : tagMap.entrySet()) {
        entityTags.add(new Tag(tag.getKey(), tag.getValue()));
    }
    return writeableEntityContainer;
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) Translation(org.openstreetmap.osmosis.tagtransform.Translation) HashMap(java.util.HashMap) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) Match(org.openstreetmap.osmosis.tagtransform.Match) TTEntityType(org.openstreetmap.osmosis.tagtransform.TTEntityType) EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) Output(org.openstreetmap.osmosis.tagtransform.Output) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

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