Search in sources :

Example 1 with Metadata

use of de.topobyte.osm4j.core.model.impl.Metadata in project osm4j-pbf by topobyte.

the class PrimParser method convert.

public List<OsmNode> convert(Osmformat.DenseNodes nodes) {
    List<OsmNode> results = new ArrayList<>(nodes.getIdCount());
    Osmformat.DenseInfo denseInfo = null;
    boolean hasVisible = false;
    if (fetchMetadata && nodes.hasDenseinfo()) {
        denseInfo = nodes.getDenseinfo();
        hasVisible = denseInfo.getVisibleCount() != 0;
    }
    long id = 0, lat = 0, lon = 0;
    int version = 0, uid = 0, userSid = 0;
    long timestamp = 0, changeset = 0;
    // Index into the keysvals array.
    int j = 0;
    for (int i = 0; i < nodes.getIdCount(); i++) {
        id += nodes.getId(i);
        lat += nodes.getLat(i);
        lon += nodes.getLon(i);
        double latf = parseLat(lat), lonf = parseLon(lon);
        List<OsmTag> tags = new ArrayList<>();
        OsmMetadata metadata = null;
        if (fetchMetadata && nodes.hasDenseinfo()) {
            version = denseInfo.getVersion(i);
            timestamp += denseInfo.getTimestamp(i);
            uid += denseInfo.getUid(i);
            userSid += denseInfo.getUserSid(i);
            changeset += denseInfo.getChangeset(i);
            boolean visible = true;
            if (hasVisible) {
                visible = denseInfo.getVisible(i);
            }
            metadata = new Metadata(version, timestamp * dateGranularity, uid, strings[userSid], changeset, visible);
        }
        // If empty, assume that nothing here has keys or vals.
        if (nodes.getKeysValsCount() > 0) {
            while (nodes.getKeysVals(j) != 0) {
                int keyid = nodes.getKeysVals(j++);
                int valid = nodes.getKeysVals(j++);
                tags.add(new Tag(strings[keyid], strings[valid]));
            }
            // Skip over the '0' delimiter.
            j++;
        }
        results.add(new Node(id, lonf, latf, tags, metadata));
    }
    return results;
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Metadata(de.topobyte.osm4j.core.model.impl.Metadata) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) Tag(de.topobyte.osm4j.core.model.impl.Tag) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Example 2 with Metadata

use of de.topobyte.osm4j.core.model.impl.Metadata 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 3 with Metadata

use of de.topobyte.osm4j.core.model.impl.Metadata in project osm4j-pbf by topobyte.

the class PrimParser method convertMetadata.

public OsmMetadata convertMetadata(Osmformat.Info info) {
    boolean visible = true;
    if (info.hasVisible() && !info.getVisible()) {
        visible = info.getVisible();
    }
    Metadata metadata = new Metadata(info.getVersion(), getTimestamp(info), info.getUid(), strings[info.getUserSid()], info.getChangeset(), visible);
    return metadata;
}
Also used : Metadata(de.topobyte.osm4j.core.model.impl.Metadata) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata)

Example 4 with Metadata

use of de.topobyte.osm4j.core.model.impl.Metadata in project osm4j-pbf by topobyte.

the class PrimParser method parseDense.

public void parseDense(Osmformat.DenseNodes nodes, OsmHandler handler) throws IOException {
    Osmformat.DenseInfo denseInfo = null;
    boolean hasVisible = false;
    if (fetchMetadata && nodes.hasDenseinfo()) {
        denseInfo = nodes.getDenseinfo();
        hasVisible = denseInfo.getVisibleCount() != 0;
    }
    long id = 0, lat = 0, lon = 0;
    int version = 0, uid = 0, userSid = 0;
    long timestamp = 0, changeset = 0;
    // Index into the keysvals array.
    int j = 0;
    for (int i = 0; i < nodes.getIdCount(); i++) {
        id += nodes.getId(i);
        lat += nodes.getLat(i);
        lon += nodes.getLon(i);
        double latf = parseLat(lat), lonf = parseLon(lon);
        List<OsmTag> tags = new ArrayList<>();
        OsmMetadata metadata = null;
        if (fetchMetadata && nodes.hasDenseinfo()) {
            version = denseInfo.getVersion(i);
            timestamp += denseInfo.getTimestamp(i);
            uid += denseInfo.getUid(i);
            userSid += denseInfo.getUserSid(i);
            changeset += denseInfo.getChangeset(i);
            boolean visible = true;
            if (hasVisible) {
                visible = denseInfo.getVisible(i);
            }
            metadata = new Metadata(version, timestamp * dateGranularity, uid, strings[userSid], changeset, visible);
        }
        // If empty, assume that nothing here has keys or vals.
        if (nodes.getKeysValsCount() > 0) {
            while (nodes.getKeysVals(j) != 0) {
                int keyid = nodes.getKeysVals(j++);
                int valid = nodes.getKeysVals(j++);
                tags.add(new Tag(strings[keyid], strings[valid]));
            }
            // Skip over the '0' delimiter.
            j++;
        }
        Node node = new Node(id, lonf, latf, tags, metadata);
        handler.handle(node);
    }
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Metadata(de.topobyte.osm4j.core.model.impl.Metadata) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) 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)4 Metadata (de.topobyte.osm4j.core.model.impl.Metadata)4 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)2 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)2 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)2 Node (de.topobyte.osm4j.core.model.impl.Node)2 Tag (de.topobyte.osm4j.core.model.impl.Tag)2 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)2 ArrayList (java.util.ArrayList)2 OsmEntity (de.topobyte.osm4j.core.model.iface.OsmEntity)1