use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project osmosis by openstreetmap.
the class OsmosisBinaryParser method parseDense.
@Override
protected void parseDense(Osmformat.DenseNodes nodes) {
long lastId = 0, lastLat = 0, lastLon = 0;
// Index into the keysvals array.
int j = 0;
// Stuff for dense info
long lasttimestamp = 0, lastchangeset = 0;
int lastuserSid = 0, lastuid = 0;
Osmformat.DenseInfo di = null;
if (nodes.hasDenseinfo()) {
di = nodes.getDenseinfo();
}
for (int i = 0; i < nodes.getIdCount(); i++) {
Node tmp;
List<Tag> tags = new ArrayList<Tag>(0);
long lat = nodes.getLat(i) + lastLat;
lastLat = lat;
long lon = nodes.getLon(i) + lastLon;
lastLon = lon;
long id = nodes.getId(i) + lastId;
lastId = id;
double latf = parseLat(lat), lonf = parseLon(lon);
// 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(getStringById(keyid), getStringById(valid)));
}
// Skip over the '0' delimiter.
j++;
}
// Handle dense info.
if (di != null) {
int uid = di.getUid(i) + lastuid;
lastuid = uid;
int userSid = di.getUserSid(i) + lastuserSid;
lastuserSid = userSid;
long timestamp = di.getTimestamp(i) + lasttimestamp;
lasttimestamp = timestamp;
int version = di.getVersion(i);
long changeset = di.getChangeset(i) + lastchangeset;
lastchangeset = changeset;
Date date = new Date(date_granularity * timestamp);
OsmUser user;
if (uid < 0) {
user = OsmUser.NONE;
} else {
user = new OsmUser(uid, getStringById(userSid));
}
tmp = new Node(new CommonEntityData(id, version, date, user, changeset, tags), latf, lonf);
} else {
tmp = new Node(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE, NOCHANGESET, tags), latf, lonf);
}
sink.process(new NodeContainer(tmp));
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project osmosis by openstreetmap.
the class OsmosisBinaryParser method parseNodes.
@Override
protected void parseNodes(List<Osmformat.Node> nodes) {
for (Osmformat.Node i : nodes) {
List<Tag> tags = new ArrayList<Tag>();
for (int j = 0; j < i.getKeysCount(); j++) {
tags.add(new Tag(getStringById(i.getKeys(j)), getStringById(i.getVals(j))));
}
// long id, int version, Date timestamp, OsmUser user,
// long changesetId, Collection<Tag> tags,
// double latitude, double longitude
Node tmp;
long id = i.getId();
double latf = parseLat(i.getLat()), lonf = parseLon(i.getLon());
if (i.hasInfo()) {
Osmformat.Info info = i.getInfo();
tmp = new Node(new CommonEntityData(id, info.getVersion(), getDate(info), getUser(info), info.getChangeset(), tags), latf, lonf);
} else {
tmp = new Node(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE, NOCHANGESET, tags), latf, lonf);
}
sink.process(new NodeContainer(tmp));
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project osmosis by openstreetmap.
the class CopyFilesetBuilder method process.
/**
* {@inheritDoc}
*/
public void process(NodeContainer nodeContainer) {
Node node;
node = nodeContainer.getEntity();
nodeWriter.writeField(node.getId());
nodeWriter.writeField(node.getVersion());
nodeWriter.writeField(node.getUser().getId());
nodeWriter.writeField(node.getTimestamp());
nodeWriter.writeField(node.getChangesetId());
nodeWriter.writeField(pointBuilder.createPoint(node.getLatitude(), node.getLongitude()));
nodeWriter.endRecord();
for (Tag tag : node.getTags()) {
nodeTagWriter.writeField(node.getId());
nodeTagWriter.writeField(tag.getKey());
nodeTagWriter.writeField(tag.getValue());
nodeTagWriter.endRecord();
}
if (enableBboxBuilder || enableLinestringBuilder) {
wayGeometryBuilder.addNodeLocation(node);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project osmosis by openstreetmap.
the class PostgreSqlWriter method flushNodes.
/**
* Flushes nodes to the database. If complete is false, this will only write
* nodes until the remaining node count is less than the multi-row insert
* statement row count. If complete is true, all remaining rows will be
* written using single row insert statements.
*
* @param complete
* If true, all data will be written to the database. If false,
* some data may be left until more data is available.
*/
private void flushNodes(boolean complete) {
while (nodeBuffer.size() >= INSERT_BULK_ROW_COUNT_NODE) {
List<Node> processedNodes;
int prmIndex;
processedNodes = new ArrayList<Node>(INSERT_BULK_ROW_COUNT_NODE);
prmIndex = 1;
for (int i = 0; i < INSERT_BULK_ROW_COUNT_NODE; i++) {
Node node;
node = nodeBuffer.remove(0);
processedNodes.add(node);
prmIndex = nodeBuilder.populateEntityParameters(bulkNodeStatement, prmIndex, node);
}
try {
bulkNodeStatement.executeUpdate();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to bulk insert nodes into the database.", e);
}
for (Node node : processedNodes) {
addNodeTags(node);
}
}
if (complete) {
while (nodeBuffer.size() > 0) {
Node node;
node = nodeBuffer.remove(0);
nodeBuilder.populateEntityParameters(singleNodeStatement, 1, node);
try {
singleNodeStatement.executeUpdate();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert a node into the database.", e);
}
addNodeTags(node);
}
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project osmosis by openstreetmap.
the class BoundSetterTest method removeExistingBoundTest.
/**
* Tests the bound removal.
*/
@Test
public void removeExistingBoundTest() {
SinkEntityInspector inspector = new SinkEntityInspector();
BoundSetter setter = new BoundSetter(null);
setter.setSink(inspector);
setter.process(new BoundContainer(new Bound("Test")));
setter.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
setter.complete();
setter.close();
EntityContainer ec = inspector.getProcessedEntities().iterator().next();
Assert.assertEquals(EntityType.Node, ec.getEntity().getType());
}
Aggregations