use of de.topobyte.osm4j.core.model.impl.Node in project osm4j-core by topobyte.
the class MapDataSetLoader method read.
public static InMemoryMapDataSet read(OsmReader reader, final boolean keepNodeTags, final boolean keepWayTags, final boolean keepRelationTags) throws OsmInputException {
final InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
final TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
final TLongObjectMap<OsmWay> ways = dataSet.getWays();
final TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
reader.setHandler(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.put(node.getId(), node);
}
@Override
public void handle(OsmWay way) throws IOException {
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.put(way.getId(), way);
}
@Override
public void handle(OsmRelation relation) throws IOException {
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.put(relation.getId(), relation);
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
use of de.topobyte.osm4j.core.model.impl.Node in project osm4j-core by topobyte.
the class ImplUtil method clone.
public static Node clone(OsmNode node) {
List<? extends OsmTag> tags = cloneTags(node);
OsmMetadata metadata = cloneMetadata(node);
return new Node(node.getId(), node.getLongitude(), node.getLatitude(), tags, metadata);
}
use of de.topobyte.osm4j.core.model.impl.Node in project osm4j-pbf by topobyte.
the class PrimParser method parseDense.
public void parseDense(Osmformat.DenseNodes nodes, OsmHandler handler) throws IOException {
Osmformat.DenseInfo denseInfo = null;
boolean hasVisible = false;
if (fetchMetadata && nodes.hasDenseinfo()) {
denseInfo = nodes.getDenseinfo();
hasVisible = denseInfo.getVisibleCount() != 0;
}
long id = 0, lat = 0, lon = 0;
int version = 0, uid = 0, userSid = 0;
long timestamp = 0, changeset = 0;
// Index into the keysvals array.
int j = 0;
for (int i = 0; i < nodes.getIdCount(); i++) {
id += nodes.getId(i);
lat += nodes.getLat(i);
lon += nodes.getLon(i);
double latf = parseLat(lat), lonf = parseLon(lon);
List<OsmTag> tags = new ArrayList<>();
OsmMetadata metadata = null;
if (fetchMetadata && nodes.hasDenseinfo()) {
version = denseInfo.getVersion(i);
timestamp += denseInfo.getTimestamp(i);
uid += denseInfo.getUid(i);
userSid += denseInfo.getUserSid(i);
changeset += denseInfo.getChangeset(i);
boolean visible = true;
if (hasVisible) {
visible = denseInfo.getVisible(i);
}
metadata = new Metadata(version, timestamp * dateGranularity, uid, strings[userSid], changeset, visible);
}
// If empty, assume that nothing here has keys or vals.
if (nodes.getKeysValsCount() > 0) {
while (nodes.getKeysVals(j) != 0) {
int keyid = nodes.getKeysVals(j++);
int valid = nodes.getKeysVals(j++);
tags.add(new Tag(strings[keyid], strings[valid]));
}
// Skip over the '0' delimiter.
j++;
}
Node node = new Node(id, lonf, latf, tags, metadata);
handler.handle(node);
}
}
Aggregations