use of de.topobyte.osm4j.core.model.iface.OsmTag in project osm4j-pbf by topobyte.
the class PbfWriter method serializeDense.
private Osmformat.PrimitiveGroup serializeDense(Collection<OsmNode> nodes) {
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
long lastlat = 0, lastlon = 0, lastid = 0;
Osmformat.DenseNodes.Builder bi = Osmformat.DenseNodes.newBuilder();
// Does anything in this block have tags?
boolean doesBlockHaveTags = false;
for (OsmNode node : nodes) {
if (node.getNumberOfTags() != 0) {
doesBlockHaveTags = true;
break;
}
}
// Find out if any of the nodes has metadata. If none does, we can omit
// the metadata completely.
boolean hasMetadata = false;
for (OsmNode node : nodes) {
if (node.getMetadata() != null) {
hasMetadata = true;
}
}
if (writeMetadata && hasMetadata) {
Osmformat.DenseInfo.Builder bdi = Osmformat.DenseInfo.newBuilder();
serializeMetadataDense(bdi, nodes);
bi.setDenseinfo(bdi);
}
for (OsmNode node : nodes) {
long id = node.getId();
int lat = mapDegrees(node.getLatitude());
int lon = mapDegrees(node.getLongitude());
bi.addId(id - lastid);
lastid = id;
bi.addLon(lon - lastlon);
lastlon = lon;
bi.addLat(lat - lastlat);
lastlat = lat;
// Then we must include tag information.
if (doesBlockHaveTags) {
for (int k = 0; k < node.getNumberOfTags(); k++) {
OsmTag t = node.getTag(k);
bi.addKeysVals(stringTable.getIndex(t.getKey()));
bi.addKeysVals(stringTable.getIndex(t.getValue()));
}
// Add delimiter.
bi.addKeysVals(0);
}
}
builder.setDense(bi);
return builder.build();
}
use of de.topobyte.osm4j.core.model.iface.OsmTag in project osm4j-pbf by topobyte.
the class PbfWriter method serializeNonDense.
private Osmformat.PrimitiveGroup serializeNonDense(Collection<OsmNode> nodes) {
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
for (OsmNode node : nodes) {
Osmformat.Node.Builder bi = Osmformat.Node.newBuilder();
bi.setId(node.getId());
bi.setLon(mapDegrees(node.getLongitude()));
bi.setLat(mapDegrees(node.getLatitude()));
for (int k = 0; k < node.getNumberOfTags(); k++) {
OsmTag t = node.getTag(k);
bi.addKeys(stringTable.getIndex(t.getKey()));
bi.addVals(stringTable.getIndex(t.getValue()));
}
if (writeMetadata && node.getMetadata() != null) {
bi.setInfo(serializeMetadata(node));
}
builder.addNodes(bi);
}
return builder.build();
}
use of de.topobyte.osm4j.core.model.iface.OsmTag in project osm4j-pbf by topobyte.
the class PbfWriter method serializeWays.
private Osmformat.PrimitiveGroup serializeWays(Collection<OsmWay> ways) {
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
for (OsmWay way : ways) {
Osmformat.Way.Builder bi = Osmformat.Way.newBuilder();
bi.setId(way.getId());
long lastid = 0;
for (int k = 0; k < way.getNumberOfNodes(); k++) {
long id = way.getNodeId(k);
bi.addRefs(id - lastid);
lastid = id;
}
for (int k = 0; k < way.getNumberOfTags(); k++) {
OsmTag t = way.getTag(k);
bi.addKeys(stringTable.getIndex(t.getKey()));
bi.addVals(stringTable.getIndex(t.getValue()));
}
if (writeMetadata && way.getMetadata() != null) {
bi.setInfo(serializeMetadata(way));
}
builder.addWays(bi);
}
return builder.build();
}
use of de.topobyte.osm4j.core.model.iface.OsmTag in project osm4j-pbf by topobyte.
the class PrimParser method convert.
public OsmWay convert(Osmformat.Way w) {
long id = w.getId();
TLongArrayList nodes = new TLongArrayList();
long lastId = 0;
for (long j : w.getRefsList()) {
nodes.add(j + lastId);
lastId = j + lastId;
}
List<OsmTag> tags = new ArrayList<>();
for (int j = 0; j < w.getKeysCount(); j++) {
tags.add(new Tag(strings[w.getKeys(j)], strings[w.getVals(j)]));
}
OsmMetadata metadata = null;
if (fetchMetadata && w.hasInfo()) {
Osmformat.Info info = w.getInfo();
metadata = convertMetadata(info);
}
return new Way(id, nodes, tags, metadata);
}
use of de.topobyte.osm4j.core.model.iface.OsmTag in project osm4j-pbf by topobyte.
the class PrimParser method convert.
public OsmNode convert(Osmformat.Node n) {
long id = n.getId();
double lat = parseLat(n.getLat());
double lon = parseLon(n.getLon());
List<OsmTag> tags = new ArrayList<>();
for (int j = 0; j < n.getKeysCount(); j++) {
tags.add(new Tag(strings[n.getKeys(j)], strings[n.getVals(j)]));
}
OsmMetadata metadata = null;
if (fetchMetadata && n.hasInfo()) {
Osmformat.Info info = n.getInfo();
metadata = convertMetadata(info);
}
return new Node(id, lon, lat, tags, metadata);
}
Aggregations