Search in sources :

Example 6 with OsmMetadata

use of de.topobyte.osm4j.core.model.iface.OsmMetadata 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 7 with OsmMetadata

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

the class PbfWriter method addUsersToStringTable.

private void addUsersToStringTable(Collection<? extends OsmEntity> entities) {
    for (OsmEntity entity : entities) {
        OsmMetadata metadata = entity.getMetadata();
        if (metadata == null) {
            continue;
        }
        String user = metadata.getUser();
        if (user == null) {
            continue;
        }
        stringTable.incr(user);
    }
}
Also used : OsmEntity(de.topobyte.osm4j.core.model.iface.OsmEntity) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) ByteString(com.google.protobuf.ByteString)

Example 8 with OsmMetadata

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

the class PbfWriter method serializeMetadataDense.

private void serializeMetadataDense(Osmformat.DenseInfo.Builder b, Collection<? extends OsmEntity> entities) {
    long lasttimestamp = 0, lastchangeset = 0;
    int lastuserSid = 0, lastuid = 0;
    for (OsmEntity e : entities) {
        OsmMetadata metadata = e.getMetadata();
        if (metadata == null) {
            metadata = new Metadata(-1, -1, -1, "", -1);
        }
        int uid = (int) metadata.getUid();
        int userSid = stringTable.getIndex(metadata.getUser());
        int timestamp = (int) (metadata.getTimestamp() / dateGranularity);
        int version = metadata.getVersion();
        long changeset = metadata.getChangeset();
        b.addVersion(version);
        b.addTimestamp(timestamp - lasttimestamp);
        lasttimestamp = timestamp;
        b.addChangeset(changeset - lastchangeset);
        lastchangeset = changeset;
        b.addUid(uid - lastuid);
        lastuid = uid;
        b.addUserSid(userSid - lastuserSid);
        lastuserSid = userSid;
    }
}
Also used : OsmEntity(de.topobyte.osm4j.core.model.iface.OsmEntity) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Metadata(de.topobyte.osm4j.core.model.impl.Metadata)

Example 9 with OsmMetadata

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

the class PbfWriter method serializeMetadata.

private Osmformat.Info.Builder serializeMetadata(OsmEntity entity) {
    Osmformat.Info.Builder b = Osmformat.Info.newBuilder();
    if (writeMetadata) {
        OsmMetadata metadata = entity.getMetadata();
        if (metadata == null) {
            return b;
        }
        if (metadata.getUid() >= 0) {
            b.setUid((int) metadata.getUid());
            b.setUserSid(stringTable.getIndex(metadata.getUser()));
        }
        b.setTimestamp((int) (metadata.getTimestamp() / dateGranularity));
        b.setVersion(metadata.getVersion());
        b.setChangeset(metadata.getChangeset());
    }
    return b;
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata)

Example 10 with OsmMetadata

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

the class PrimParser method convert.

public OsmRelation convert(Osmformat.Relation r) {
    long id = r.getId();
    long lastMid = 0;
    List<OsmTag> tags = new ArrayList<>();
    for (int j = 0; j < r.getKeysCount(); j++) {
        tags.add(new Tag(strings[r.getKeys(j)], strings[r.getVals(j)]));
    }
    List<RelationMember> members = new ArrayList<>();
    for (int j = 0; j < r.getMemidsCount(); j++) {
        long mid = lastMid + r.getMemids(j);
        lastMid = mid;
        String role = strings[r.getRolesSid(j)];
        Osmformat.Relation.MemberType type = r.getTypes(j);
        EntityType t = getType(type);
        RelationMember member = new RelationMember(mid, t, role);
        members.add(member);
    }
    OsmMetadata metadata = null;
    if (fetchMetadata && r.hasInfo()) {
        Osmformat.Info info = r.getInfo();
        metadata = convertMetadata(info);
    }
    return new Relation(id, members, tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) EntityType(de.topobyte.osm4j.core.model.iface.EntityType) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) RelationMember(de.topobyte.osm4j.core.model.impl.RelationMember) Tag(de.topobyte.osm4j.core.model.impl.Tag) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Aggregations

OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)12 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)7 ArrayList (java.util.ArrayList)6 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)5 Tag (de.topobyte.osm4j.core.model.impl.Tag)5 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)5 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)4 Metadata (de.topobyte.osm4j.core.model.impl.Metadata)4 Node (de.topobyte.osm4j.core.model.impl.Node)4 OsmEntity (de.topobyte.osm4j.core.model.iface.OsmEntity)2 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)2 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)2 Relation (de.topobyte.osm4j.core.model.impl.Relation)2 RelationMember (de.topobyte.osm4j.core.model.impl.RelationMember)2 Way (de.topobyte.osm4j.core.model.impl.Way)2 ByteString (com.google.protobuf.ByteString)1 TLongList (com.slimjars.dist.gnu.trove.list.TLongList)1 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)1