Search in sources :

Example 86 with Node

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));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) ArrayList(java.util.ArrayList) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Osmformat(crosby.binary.Osmformat) Date(java.util.Date) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 87 with Node

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));
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) ArrayList(java.util.ArrayList) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Osmformat(crosby.binary.Osmformat)

Example 88 with Node

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);
    }
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 89 with 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);
        }
    }
}
Also used : SQLException(java.sql.SQLException) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 90 with 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());
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)52 Test (org.junit.Test)27 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)26 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)21 Date (java.util.Date)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)17 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)16 Node (org.flyte.api.v1.Node)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)14 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)14 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)13 TaskNode (org.flyte.api.v1.TaskNode)10 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)10 List (java.util.List)9 Map (java.util.Map)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)9 Node (ch.ethz.globis.phtree.v16.Node)8