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)));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
Aggregations