Search in sources :

Example 1 with PrimitiveGroup

use of com.baremaps.osm.binary.Osmformat.PrimitiveGroup 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)

Example 2 with PrimitiveGroup

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

the class DataBlockReader method readWays.

/**
 * Read the ways with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readWays(Consumer<Way> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Way way : group.getWaysList()) {
            long id = way.getId();
            int version = way.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(way.getInfo().getTimestamp());
            long changeset = way.getInfo().getChangeset();
            int uid = way.getInfo().getUid();
            Map<String, String> tags = getTags(way.getKeysList(), way.getValsList());
            long nid = 0;
            List<Long> nodes = new ArrayList<>();
            for (int index = 0; index < way.getRefsCount(); index++) {
                nid = nid + way.getRefs(index);
                nodes.add(nid);
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Way(id, info, tags, nodes));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info) Way(com.baremaps.osm.domain.Way)

Example 3 with PrimitiveGroup

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

the class DataBlockReader method readRelations.

/**
 * Read the relations with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readRelations(Consumer<Relation> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Relation relation : group.getRelationsList()) {
            long id = relation.getId();
            int version = relation.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(relation.getInfo().getTimestamp());
            long changeset = relation.getInfo().getChangeset();
            int uid = relation.getInfo().getUid();
            Map<String, String> tags = getTags(relation.getKeysList(), relation.getValsList());
            long mid = 0;
            List<Member> members = new ArrayList<>();
            for (int j = 0; j < relation.getMemidsCount(); j++) {
                mid = mid + relation.getMemids(j);
                String role = getString(relation.getRolesSid(j));
                MemberType type = type(relation.getTypes(j));
                members.add(new Member(mid, type, role));
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Relation(id, info, tags, members));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info) Relation(com.baremaps.osm.domain.Relation) MemberType(com.baremaps.osm.domain.Member.MemberType) Member(com.baremaps.osm.domain.Member)

Example 4 with PrimitiveGroup

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

the class DataBlockReader method readNodes.

/**
 * Read the nodes with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readNodes(Consumer<Node> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Node node : group.getNodesList()) {
            long id = node.getId();
            int version = node.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(node.getInfo().getTimestamp());
            long changeset = node.getInfo().getChangeset();
            int uid = node.getInfo().getUid();
            Map<String, String> tags = new HashMap<>();
            for (int t = 0; t < node.getKeysList().size(); t++) {
                tags.put(getString(node.getKeysList().get(t)), getString(node.getKeysList().get(t)));
            }
            double lon = getLon(node.getLon());
            double lat = getLat(node.getLat());
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Node(id, info, tags, lon, lat));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info)

Aggregations

Osmformat (com.baremaps.osm.binary.Osmformat)4 PrimitiveGroup (com.baremaps.osm.binary.Osmformat.PrimitiveGroup)4 Info (com.baremaps.osm.domain.Info)4 LocalDateTime (java.time.LocalDateTime)3 Node (com.baremaps.osm.domain.Node)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DenseNodes (com.baremaps.osm.binary.Osmformat.DenseNodes)1 Member (com.baremaps.osm.domain.Member)1 MemberType (com.baremaps.osm.domain.Member.MemberType)1 Relation (com.baremaps.osm.domain.Relation)1 Way (com.baremaps.osm.domain.Way)1