Package org.openstreetmap.josm.data.osm

Examples of org.openstreetmap.josm.data.osm.Node


    @Override
    public void visit(Way w) {
        if (!w.isUsable()) return;

        Node lastN = null;
        for (Node n : w.getNodes()) {
            if (lastN == null) {
                lastN = n;
                continue;
            }
View Full Code Here


        Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
        if (it.hasNext()) {
            Way w = (Way) it.next();
            Way wnew = new Way(w);
            wnew.setNodes(null);
            Node lastN = null;
            for (Node n : w.getNodes()) {
                if (lastN == null) {
                    wnew.addNode(n);
                } else if (n == lastN) {
                    // Skip this node
View Full Code Here

                return;
            }
            selectedNodes.addAll(nearestNodes);
        }

        Node targetNode = selectTargetNode(selectedNodes);
        Node targetLocationNode = selectTargetLocationNode(selectedNodes);
        Command cmd = mergeNodes(Main.main.getEditLayer(), selectedNodes, targetNode, targetLocationNode);
        if (cmd != null) {
            Main.main.undoRedo.add(cmd);
            Main.main.getEditLayer().data.setSelected(targetNode);
        }
View Full Code Here

            errors.add(new TestError(this, Severity.ERROR, tr("Way contains segment twice"),
                    DUPLICATE_WAY_SEGMENT, Collections.singleton(w), duplicateWaySegment));
            return;
        }

        Node lastN = null;
        int i = -2;
        for (Node n : w.getNodes()) {
            i++;
            if (lastN == null) {
                lastN = n;
View Full Code Here

        if (size == 0)
            throw new IllegalArgumentException("empty list");

        switch (Main.pref.getInteger("merge-nodes.mode", 0)) {
        case 0:
            Node targetNode = candidates.get(size - 1);
            for (final Node n : candidates) { // pick last one
                targetNode = n;
            }
            return targetNode;
        case 1:
            double east1 = 0, north1 = 0;
            for (final Node n : candidates) {
                east1 += n.getEastNorth().east();
                north1 += n.getEastNorth().north();
            }

            return new Node(new EastNorth(east1 / size, north1 / size));
        case 2:
            final double[] weights = new double[size];

            for (int i = 0; i < size; i++) {
                final LatLon c1 = candidates.get(i).getCoor();
                for (int j = i + 1; j < size; j++) {
                    final LatLon c2 = candidates.get(j).getCoor();
                    final double d = c1.distance(c2);
                    weights[i] += d;
                    weights[j] += d;
                }
            }

            double east2 = 0, north2 = 0, weight = 0;
            for (int i = 0; i < size; i++) {
                final EastNorth en = candidates.get(i).getEastNorth();
                final double w = weights[i];
                east2 += en.east() * w;
                north2 += en.north() * w;
                weight += w;
            }

            return new Node(new EastNorth(east2 / weight, north2 / weight));
        default:
            throw new RuntimeException("unacceptable merge-nodes.mode");
        }

    }
View Full Code Here

     *
     * @param candidates the collection of candidate nodes
     * @return the selected target node
     */
    public static Node selectTargetNode(Collection<Node> candidates) {
        Node oldestNode = null;
        Node targetNode = null;
        Node lastNode = null;
        for (Node n : candidates) {
            if (!n.isNew()) {
                // Among existing nodes, try to keep the oldest used one
                if (!n.getReferrers().isEmpty()) {
                    if (targetNode == null) {
View Full Code Here

        if (nodes == null) {
            return;
        }
        Set<Node> allNodes = new HashSet<>(nodes);
        allNodes.add(targetLocationNode);
        Node target;
        if (nodes.contains(targetLocationNode) && !targetLocationNode.isNew()) {
            target = targetLocationNode; // keep existing targetLocationNode as target to avoid unnecessary changes (see #2447)
        } else {
            target = selectTargetNode(allNodes);
        }
View Full Code Here

            // build the commands
            //
            if (targetNode != targetLocationNode) {
                LatLon targetLocationCoor = targetLocationNode.getCoor();
                if (!targetNode.getCoor().equals(targetLocationCoor)) {
                    Node newTargetNode = new Node(targetNode);
                    newTargetNode.setCoor(targetLocationCoor);
                    cmds.add(new ChangeCommand(targetNode, newTargetNode));
                }
            }
            cmds.addAll(resultion);
            if (!nodesToDelete.isEmpty()) {
View Full Code Here

        if (selectedNodes.isEmpty())
            return null;

        // Special case - one of the selected ways touches (not cross) way that we want to split
        if (selectedNodes.size() == 1) {
            Node n = selectedNodes.get(0);
            List<Way> referedWays = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);
            Way inTheMiddle = null;
            boolean foundSelected = false;
            for (Way w: referedWays) {
                if (selectedWays.contains(w)) {
                    foundSelected = true;
View Full Code Here

        List<Node> currentWayChunk = new ArrayList<>();
        wayChunks.add(currentWayChunk);

        Iterator<Node> it = wayToSplit.getNodes().iterator();
        while (it.hasNext()) {
            Node currentNode = it.next();
            boolean atEndOfWay = currentWayChunk.isEmpty() || !it.hasNext();
            currentWayChunk.add(currentNode);
            if (nodeSet.contains(currentNode) && !atEndOfWay) {
                currentWayChunk = new ArrayList<>();
                currentWayChunk.add(currentNode);
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.data.osm.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.