Search in sources :

Example 1 with DenseNodes

use of com.baremaps.osm.binary.Osmformat.DenseNodes in project baremaps by baremaps.

the class DataBlockReader method readDenseNodes.

/**
 * Read the dense nodes with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readDenseNodes(Consumer<Node> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        DenseNodes denseNodes = group.getDense();
        long id = 0;
        long lat = 0;
        long lon = 0;
        long timestamp = 0;
        long changeset = 0;
        int sid = 0;
        int uid = 0;
        // Index into the keysvals array.
        int j = 0;
        for (int i = 0; i < denseNodes.getIdCount(); i++) {
            id = denseNodes.getId(i) + id;
            Osmformat.DenseInfo denseInfo = denseNodes.getDenseinfo();
            int version = denseInfo.getVersion(i);
            uid = denseInfo.getUid(i) + uid;
            sid = denseInfo.getUserSid(i) + sid;
            timestamp = denseInfo.getTimestamp(i) + timestamp;
            changeset = denseInfo.getChangeset(i) + changeset;
            lat = denseNodes.getLat(i) + lat;
            lon = denseNodes.getLon(i) + lon;
            // If empty, assume that nothing here has keys or vals.
            Map<String, String> tags = new HashMap<>();
            if (denseNodes.getKeysValsCount() > 0) {
                while (denseNodes.getKeysVals(j) != 0) {
                    int keyid = denseNodes.getKeysVals(j++);
                    int valid = denseNodes.getKeysVals(j++);
                    tags.put(getString(keyid), getString(valid));
                }
                // Skip over the '0' delimiter.
                j++;
            }
            Info info = new Info(version, getTimestamp(timestamp), changeset, uid);
            consumer.accept(new Node(id, info, tags, getLon(lon), getLat(lat)));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) DenseNodes(com.baremaps.osm.binary.Osmformat.DenseNodes) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info)

Aggregations

Osmformat (com.baremaps.osm.binary.Osmformat)1 DenseNodes (com.baremaps.osm.binary.Osmformat.DenseNodes)1 PrimitiveGroup (com.baremaps.osm.binary.Osmformat.PrimitiveGroup)1 Info (com.baremaps.osm.domain.Info)1 Node (com.baremaps.osm.domain.Node)1 HashMap (java.util.HashMap)1