Package org.openstreetmap.josm.data.osm

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


    private GeneralPath createPath(List<Node> nodes) {
        GeneralPath result = new GeneralPath();
        result.moveTo((float) nodes.get(0).getCoor().lat(), (float) nodes.get(0).getCoor().lon());
        for (int i=1; i<nodes.size(); i++) {
            Node n = nodes.get(i);
            result.lineTo((float) n.getCoor().lat(), (float) n.getCoor().lon());
        }
        return result;
    }
View Full Code Here


            return ret;
        for (int i = 1; i < size; ++i) {
            if(i < size-1) {
                addNode(w.getNode(i), middlenodes);
            }
            Node a = w.getNode(i-1);
            Node b = w.getNode(i);
            if (a.isDrawable() && b.isDrawable()) {
                MyWaySegment ws = new MyWaySegment(w, a, b);
                if (ws.isBoundary || ws.isAbandoned) {
                    continue;
                }
                ret.add(ws);
View Full Code Here

        Collection<Command> cmds = new LinkedList<>();
        EastNorth center = null;

        if (nodes.size() == 2) {
            // diameter: two single nodes needed or a way with two nodes
            Node   n1 = nodes.get(0);
            double x1 = n1.getEastNorth().east();
            double y1 = n1.getEastNorth().north();
            Node   n2 = nodes.get(1);
            double x2 = n2.getEastNorth().east();
            double y2 = n2.getEastNorth().north();

            // calculate the center (xc/yc)
            double xc = 0.5 * (x1 + x2);
            double yc = 0.5 * (y1 + y2);
            center = new EastNorth(xc, yc);
        } else {
            // triangle: three single nodes needed or a way with three nodes
            center = Geometry.getCenter(nodes);
            if (center == null) {
                notifyNodesNotOnCircle();
                return;
            }
        }

        // calculate the radius (r)
        EastNorth n1 = nodes.get(0).getEastNorth();
        double r = Math.sqrt(Math.pow(center.east()-n1.east(),2) +
                Math.pow(center.north()-n1.north(),2));

        // Order nodes by angle
        PolarNode[] angles = new PolarNode[nodes.size()];
        for(int i = 0; i < nodes.size(); i++) {
            angles[i] = new PolarNode(center, nodes.get(i));
        }
        Arrays.sort(angles, new PolarNodeComparator());
        int[] count = distributeNodes(angles,
                numberOfNodesInCircle >= nodes.size() ? numberOfNodesInCircle - nodes.size() : 0);

        // build a way for the circle
        List<Node> wayToAdd = new ArrayList<>();
        for(int i = 0; i < nodes.size(); i++) {
            wayToAdd.add(angles[i].node);
            double delta = angles[(i+1) % nodes.size()].a - angles[i].a;
            if(delta < 0)
                delta += 2*Math.PI;
            for(int j = 0; j < count[i]; j++) {
                double alpha = angles[i].a + (j+1)*delta/(count[i]+1);
                double x = center.east() + r*Math.cos(alpha);
                double y = center.north() + r*Math.sin(alpha);
                LatLon ll = Main.getProjection().eastNorth2latlon(new EastNorth(x,y));
                if (ll.isOutSideWorld()) {
                    notifyNodesNotOnCircle();
                    return;
                }
                Node n = new Node(ll);
                wayToAdd.add(n);
                cmds.add(new AddCommand(n));
            }
        }
        wayToAdd.add(wayToAdd.get(0)); // close the circle
View Full Code Here

                    typeMap.put(type, false);
                }

                for (OsmPrimitive p : mm.get(tagSet)) {
                    if (p.getType()==OsmPrimitiveType.NODE) {
                        Node n = (Node) p;
                        List<OsmPrimitive> lp=n.getReferrers();
                        for (OsmPrimitive sp: lp) {
                            if (sp.getType()==OsmPrimitiveType.WAY) {
                                boolean typed = false;
                                Way w=(Way) sp;
                                Map<String, String> keys = w.getKeys();
View Full Code Here

                potentialDuplicates.put(n);
            } else if (potentialDuplicates.get(n) instanceof Node) {
                // we have an additional node at the same position. Create an extra
                // object to keep track of the nodes at this position.
                //
                Node n1 = (Node)potentialDuplicates.get(n);
                List<Node> nodes = new ArrayList<>(2);
                nodes.add(n1);
                nodes.add(n);
                potentialDuplicates.put(nodes);
            } else if (potentialDuplicates.get(n) instanceof List<?>) {
View Full Code Here

        }

        // Merge only if at least 2 nodes remain
        if (nodes.size() >= 2) {
            // Use first existing node or first node if all nodes are new
            Node target = null;
            for (Node n: nodes) {
                if (!n.isNew()) {
                    target = n;
                    break;
                }
View Full Code Here

                default:
                    errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE,
                            l, Collections.singletonList(m)));
                }
            } else if (m.isNode()) {
                Node n = m.getNode();
                if ("via".equals(m.getRole())) {
                    if (!via.isEmpty()) {
                        if (via.get(0) instanceof Node) {
                            morevia = true;
                        } else {
                            mixvia = true;
                        }
                    } else {
                        via.add(n);
                    }
                } else {
                    errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE,
                            l, Collections.singletonList(m)));
                }
            } else {
                errors.add(new TestError(this, Severity.WARNING, tr("Unknown member type"), UNKNOWN_TYPE,
                        l, Collections.singletonList(m)));
            }
        }
        if (morefrom) {
            errors.add(new TestError(this, Severity.ERROR, tr("More than one \"from\" way found"), MORE_FROM, r));
        }
        if (moreto) {
            errors.add(new TestError(this, Severity.ERROR, tr("More than one \"to\" way found"), MORE_TO, r));
        }
        if (morevia) {
            errors.add(new TestError(this, Severity.ERROR, tr("More than one \"via\" node found"), MORE_VIA, r));
        }
        if (mixvia) {
            errors.add(new TestError(this, Severity.ERROR, tr("Cannot mix node and way for role \"via\""), MIX_VIA, r));
        }

        if (fromWay == null) {
            errors.add(new TestError(this, Severity.ERROR, tr("No \"from\" way found"), NO_FROM, r));
            return;
        }
        if (toWay == null) {
            errors.add(new TestError(this, Severity.ERROR, tr("No \"to\" way found"), NO_TO, r));
            return;
        }
        if (via.isEmpty()) {
            errors.add(new TestError(this, Severity.ERROR, tr("No \"via\" node or way found"), NO_VIA, r));
            return;
        }

        if (via.get(0) instanceof Node) {
            final Node viaNode = (Node) via.get(0);
            final Way viaPseudoWay = new Way();
            viaPseudoWay.addNode(viaNode);
            checkIfConnected(fromWay, viaPseudoWay,
                    tr("The \"from\" way does not start or end at a \"via\" node."), FROM_VIA_NODE);
            if (toWay.isOneway() != 0 && viaNode.equals(toWay.lastNode(true))) {
                errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r));
                return;
            }
            checkIfConnected(viaPseudoWay, toWay,
                    tr("The \"to\" way does not start or end at a \"via\" node."), TO_VIA_NODE);
View Full Code Here

    }

    @Override
    public void endTest() {
        for (Way c1 : coastlines) {
            Node head = c1.firstNode();
            Node tail = c1.lastNode();

            if (c1.getNodesCount() == 0 || head.equals(tail)) {
                continue;
            }

            int headWays = 0;
            int tailWays = 0;
            boolean headReversed = false;
            boolean tailReversed = false;
            boolean headUnordered = false;
            boolean tailUnordered = false;
            Way next = null;
            Way prev = null;

            for (Way c2 : coastlines) {
                if (c1 == c2) {
                    continue;
                }

                if (c2.containsNode(head)) {
                    headWays++;
                    next = c2;

                    if (head.equals(c2.firstNode())) {
                        headReversed = true;
                    } else if (!head.equals(c2.lastNode())) {
                        headUnordered = true;
                    }
                }

                if (c2.containsNode(tail)) {
                    tailWays++;
                    prev = c2;

                    if (tail.equals(c2.lastNode())) {
                        tailReversed = true;
                    } else if (!tail.equals(c2.firstNode())) {
                        tailUnordered = true;
                    }
                }
            }

            // To avoid false positives on upload (only modified primitives
            // are visited), we have to check possible connection to ways
            // that are not in the set of validated primitives.
            if (headWays == 0) {
                Collection<OsmPrimitive> refs = head.getReferrers();
                for (OsmPrimitive ref : refs) {
                    if (ref != c1 && isCoastline(ref)) {
                        // ref cannot be in <code>coastlines</code>, otherwise we would
                        // have picked it up already
                        headWays++;
                        next = (Way) ref;

                        if (head.equals(next.firstNode())) {
                            headReversed = true;
                        } else if (!head.equals(next.lastNode())) {
                            headUnordered = true;
                        }
                    }
                }
            }
            if (tailWays == 0) {
                Collection<OsmPrimitive> refs = tail.getReferrers();
                for (OsmPrimitive ref : refs) {
                    if (ref != c1 && isCoastline(ref)) {
                        tailWays++;
                        prev = (Way) ref;

                        if (tail.equals(prev.lastNode())) {
                            tailReversed = true;
                        } else if (!tail.equals(prev.firstNode())) {
                            tailUnordered = true;
                        }
                    }
                }
            }

            List<OsmPrimitive> primitives = new ArrayList<>();
            primitives.add(c1);

            if (headWays == 0 || tailWays == 0) {
                List<OsmPrimitive> highlight = new ArrayList<>();

                if (headWays == 0 && head.getCoor().isIn(downloadedArea)) {
                    highlight.add(head);
                }
                if (tailWays == 0 && tail.getCoor().isIn(downloadedArea)) {
                    highlight.add(tail);
                }

                if (!highlight.isEmpty()) {
                    errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"),
View Full Code Here

    protected void processWaysAfterParsing() throws IllegalDataException{
        for (Long externalWayId: ways.keySet()) {
            Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY));
            List<Node> wayNodes = new ArrayList<>();
            for (long id : ways.get(externalWayId)) {
                Node n = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));
                if (n == null) {
                    if (id <= 0)
                        throw new IllegalDataException (
                                tr("Way with external ID ''{0}'' includes missing node with external ID ''{1}''.",
                                        externalWayId,
                                        id));
                    // create an incomplete node if necessary
                    //
                    n = (Node)ds.getPrimitiveById(id,OsmPrimitiveType.NODE);
                    if (n == null) {
                        n = new Node(id);
                        ds.addPrimitive(n);
                    }
                }
                if (n.isDeleted()) {
                    Main.info(tr("Deleted node {0} is part of way {1}", id, w.getId()));
                } else {
                    wayNodes.add(n);
                }
            }
View Full Code Here

                    //
                    primitive = ds.getPrimitiveById(rm.getMemberId(), rm.getMemberType());
                    if (primitive == null) {
                        switch (rm.getMemberType()) {
                        case NODE:
                            primitive = new Node(rm.getMemberId()); break;
                        case WAY:
                            primitive = new Way(rm.getMemberId()); break;
                        case RELATION:
                            primitive = new Relation(rm.getMemberId()); break;
                        default: throw new AssertionError(); // can't happen
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.