use of com.baremaps.osm.domain.Info in project baremaps by baremaps.
the class OsmXmlSpliterator method readNode.
private Node readNode() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
// read the content of the node
Map<String, String> tags = new HashMap<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
default:
readUnknownElement();
break;
}
}
return new Node(id, info, tags, longitude, latitude);
}
use of com.baremaps.osm.domain.Info 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.domain.Info 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.domain.Info 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.domain.Info in project baremaps by baremaps.
the class OsmChangeSpliterator method readRelation.
private Relation readRelation() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
// read the content of the node
Map<String, String> tags = new HashMap<>();
List<Member> members = new ArrayList<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
case ELEMENT_NAME_MEMBER:
readRelationMember(members);
break;
default:
readUnknownElement();
break;
}
}
return new Relation(id, info, tags, members);
}
Aggregations