Class Way

    • Constructor Detail

      • Way

        Way​(long id,
            boolean allowNegative)
      • Way

        public Way()
        Constructs a new Way with id 0.
        Since:
        86
      • Way

        public Way​(Way original,
                   boolean clearMetadata,
                   boolean copyNodes)
        Constructs a new Way from an existing Way. This adds links from all way nodes to the clone. See #19885 for possible memory leaks.
        Parameters:
        original - The original Way to be identically cloned. Must not be null
        clearMetadata - If true, clears the OSM id and other metadata as defined by OsmPrimitive.clearOsmMetadata(). If false, does nothing
        copyNodes - whether to copy nodes too
        Since:
        16212
      • Way

        public Way​(Way original,
                   boolean clearMetadata)
        Constructs a new Way from an existing Way. This adds links from all way nodes to the clone. See #19885 for possible memory leaks.
        Parameters:
        original - The original Way to be identically cloned. Must not be null
        clearMetadata - If true, clears the OSM id and other metadata as defined by OsmPrimitive.clearOsmMetadata(). If false, does nothing
        Since:
        2410
      • Way

        public Way​(Way original)
        Constructs a new Way from an existing Way (including its id). This adds links from all way nodes to the clone. See #19885 for possible memory leaks.
        Parameters:
        original - The original Way to be identically cloned. Must not be null
        Since:
        86
      • Way

        public Way​(long id)
        Constructs a new Way for the given id. If the id > 0, the way is marked as incomplete. If id == 0 then way is marked as new
        Parameters:
        id - the id. >= 0 required
        Throws:
        java.lang.IllegalArgumentException - if id < 0
        Since:
        343
      • Way

        public Way​(long id,
                   int version)
        Constructs a new Way with given id and version.
        Parameters:
        id - the id. >= 0 required
        version - the version
        Throws:
        java.lang.IllegalArgumentException - if id < 0
        Since:
        2620
    • Method Detail

      • getNodes

        public java.util.List<NodegetNodes()
        Description copied from interface: IWay
        Returns the list of nodes in this way.
        Specified by:
        getNodes in interface IWay<Node>
        Returns:
        the list of nodes in this way
      • setNodes

        public void setNodes​(java.util.List<Node> nodes)
        Description copied from interface: IWay
        Set new list of nodes to way. This method is preferred to multiple calls to addNode/removeNode and similar methods because nodes are internally saved as array which means lower memory overhead but also slower modifying operations.
        Specified by:
        setNodes in interface IWay<Node>
        Parameters:
        nodes - New way nodes. Can be null, in that case all way nodes are removed
      • removeDouble

        private static java.util.List<NoderemoveDouble​(java.util.List<Node> nodes)
        Prevent directly following identical nodes in ways.
        Parameters:
        nodes - list of nodes
        Returns:
        nodes with consecutive identical nodes removed
      • getNodesCount

        public int getNodesCount()
        Description copied from interface: IWay
        Replies the number of nodes in this way.
        Specified by:
        getNodesCount in interface IWay<Node>
        Returns:
        the number of nodes in this way.
      • getNode

        public Node getNode​(int index)
        Description copied from interface: IWay
        Replies the node at position index.
        Specified by:
        getNode in interface IWay<Node>
        Parameters:
        index - the position
        Returns:
        the node at position index
      • getNodeId

        public long getNodeId​(int idx)
        Description copied from interface: IWay
        Returns id of the node at given index.
        Specified by:
        getNodeId in interface IWay<Node>
        Parameters:
        idx - node index
        Returns:
        id of the node at given index
      • getNodeIds

        public java.util.List<java.lang.Long> getNodeIds()
        Description copied from interface: IWay
        Returns the list of node ids in this way.
        Specified by:
        getNodeIds in interface IWay<Node>
        Returns:
        the list of node ids in this way
      • containsNode

        public boolean containsNode​(Node node)
        Replies true if this way contains the node node, false otherwise. Replies false if node is null.
        Parameters:
        node - the node. May be null.
        Returns:
        true if this way contains the node node, false otherwise
        Since:
        1911
      • getNeighbours

        public java.util.Set<NodegetNeighbours​(Node node)
        Return nodes adjacent to node
        Parameters:
        node - the node. May be null.
        Returns:
        Set of nodes adjacent to node
        Since:
        4671
      • getNodePairs

        public java.util.List<Pair<Node,​Node>> getNodePairs​(boolean sort)
        Replies the ordered List of chunks of this way. Each chunk is replied as a Pair of nodes.
        Parameters:
        sort - If true, the nodes of each pair are sorted as defined by Pair.sort(org.openstreetmap.josm.tools.Pair<T, T>). If false, Pair.a and Pair.b are in the way order (i.e for a given Pair(n), Pair(n-1).b == Pair(n).a, Pair(n).b == Pair(n+1).a, etc.)
        Returns:
        The ordered list of chunks of this way.
        Since:
        3348
      • accept

        public void accept​(OsmPrimitiveVisitor visitor)
        Description copied from class: OsmPrimitive
        Implementation of the visitor scheme. Subclasses have to call the correct visitor function.
        Specified by:
        accept in class OsmPrimitive
        Parameters:
        visitor - The visitor from which the visit() function must be called.
      • load

        public void load​(PrimitiveData data)
        Description copied from class: OsmPrimitive
        Loads (clone) this primitive from provided PrimitiveData
        Overrides:
        load in class OsmPrimitive
        Parameters:
        data - The object which should be cloned
      • save

        public WayData save()
        Description copied from class: OsmPrimitive
        Save parameters of this primitive to the transport object
        Specified by:
        save in class OsmPrimitive
        Returns:
        The saved object data
      • cloneFrom

        public void cloneFrom​(OsmPrimitive osm,
                              boolean copyNodes)
        Description copied from class: OsmPrimitive
        Get and write all attributes from the parameter. Does not fire any listener, so use this only in the data initializing phase
        Overrides:
        cloneFrom in class OsmPrimitive
        Parameters:
        osm - other primitive
        copyNodes - whether to copy child primitives too
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • removeNode

        public void removeNode​(Node n)
        Removes the given Node from this way. Ignored, if n is null.
        Parameters:
        n - The node to remove. Ignored, if null
        Since:
        1463
      • removeNodes

        public void removeNodes​(java.util.Set<? extends Node> selection)
        Removes the given set of nodes from this way. Ignored, if selection is null.
        Parameters:
        selection - The selection of nodes to remove. Ignored, if null
        Since:
        5408
      • calculateRemoveNodes

        public java.util.List<NodecalculateRemoveNodes​(java.util.Set<? extends Node> selection)
        Calculate the remaining nodes after a removal of the given set of nodes from this way.
        Parameters:
        selection - The selection of nodes to remove. Ignored, if null
        Returns:
        result of the removal, can be empty
        Since:
        17102
      • addNode

        public void addNode​(Node n)
        Adds a node to the end of the list of nodes. Ignored, if n is null.
        Parameters:
        n - the node. Ignored, if null
        Throws:
        java.lang.IllegalStateException - if this way is marked as incomplete. We can't add a node to an incomplete way
        Since:
        1313
      • addNode

        public void addNode​(int offs,
                            Node n)
        Adds a node at position offs.
        Parameters:
        offs - the offset
        n - the node. Ignored, if null.
        Throws:
        java.lang.IllegalStateException - if this way is marked as incomplete. We can't add a node to an incomplete way
        java.lang.IndexOutOfBoundsException - if offs is out of bounds
        Since:
        1313
      • setDeleted

        public void setDeleted​(boolean deleted)
        Description copied from interface: IPrimitive
        Sets whether this primitive is deleted or not.

        Also marks this primitive as modified if deleted is true.

        Specified by:
        setDeleted in interface IPrimitive
        Overrides:
        setDeleted in class OsmPrimitive
        Parameters:
        deleted - true, if this primitive is deleted; false, otherwise
      • isClosed

        public boolean isClosed()
        Description copied from interface: IWay
        Determines if this way is closed.
        Specified by:
        isClosed in interface IWay<Node>
        Returns:
        true if this way is closed, false otherwise
      • isArea

        public boolean isArea()
        Determines if this way denotes an area (closed way with at least three distinct nodes).
        Returns:
        true if this way is closed and contains at least three distinct nodes
        Since:
        5490
        See Also:
        isClosed()
      • firstNode

        public Node firstNode()
        Description copied from interface: IWay
        Returns the first node of this way. The result equals getNode(0).
        Specified by:
        firstNode in interface IWay<Node>
        Returns:
        the first node of this way
      • isFirstLastNode

        public boolean isFirstLastNode​(INode n)
        Description copied from interface: IWay
        Replies true if the given node is the first or the last one of this way, false otherwise.
        Specified by:
        isFirstLastNode in interface IWay<Node>
        Parameters:
        n - The node to test
        Returns:
        true if the n is the first or the last node, false otherwise.
      • isInnerNode

        public boolean isInnerNode​(INode n)
        Description copied from interface: IWay
        Replies true if the given node is an inner node of this way, false otherwise.
        Specified by:
        isInnerNode in interface IWay<Node>
        Parameters:
        n - The node to test
        Returns:
        true if the n is an inner node, false otherwise.
      • setDataset

        void setDataset​(DataSet dataSet)
        Description copied from class: OsmPrimitive
        This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods
        Overrides:
        setDataset in class OsmPrimitive
        Parameters:
        dataSet - the parent dataset
      • getBBox

        public BBox getBBox()
        Description copied from interface: IPrimitive
        Fetches the bounding box of the primitive. Since 17752, the returned bounding box might be immutable, i.e., modifying calls throw an UnsupportedOperationException.
        Specified by:
        getBBox in interface IPrimitive
        Specified by:
        getBBox in interface IQuadBucketType
        Returns:
        Bounding box of the object
      • addToBBox

        protected void addToBBox​(BBox box,
                                 java.util.Set<PrimitiveId> visited)
        Description copied from class: OsmPrimitive
        If necessary, extend the bbox to contain this primitive
        Specified by:
        addToBBox in class OsmPrimitive
        Parameters:
        box - a bbox instance
        visited - a set of visited members or null
      • hasIncompleteNodes

        public boolean hasIncompleteNodes()
        Description copied from interface: IWay
        Replies true if this way has incomplete nodes, false otherwise.
        Specified by:
        hasIncompleteNodes in interface IWay<Node>
        Returns:
        true if this way has incomplete nodes, false otherwise.
      • hasOnlyLocatableNodes

        public boolean hasOnlyLocatableNodes()
        Replies true if all nodes of the way have known lat/lon, false otherwise.
        Returns:
        true if all nodes of the way have known lat/lon, false otherwise
        Since:
        13033
      • isDrawable

        public boolean isDrawable()
        Description copied from interface: IPrimitive
        Determines if this object is drawable.

        A primitive is drawable if all conditions are met:

        • type and id is known
        • tags are known
        • it is not deleted
        • it is not hidden by a filter
        • for nodes: lat/lon are known
        • for ways: all nodes are known and complete
        • for relations: all members are known and complete
        Specified by:
        isDrawable in interface IPrimitive
        Overrides:
        isDrawable in class AbstractPrimitive
        Returns:
        true if this object is drawable
      • segmentLengths

        private java.util.stream.DoubleStream segmentLengths()
        Get the segment lengths as a stream
        Returns:
        The stream of segment lengths (ordered)
      • isOneway

        public int isOneway()
        Tests if this way is a oneway.
        Returns:
        1 if the way is a oneway, -1 if the way is a reversed oneway, 0 otherwise.
        Since:
        5199
      • firstNode

        public Node firstNode​(boolean respectOneway)
        Replies the first node of this way, respecting or not its oneway state.
        Parameters:
        respectOneway - If true and if this way is a reversed oneway, replies the last node. Otherwise, replies the first node.
        Returns:
        the first node of this way, according to respectOneway and its oneway state.
        Since:
        5199
      • lastNode

        public Node lastNode​(boolean respectOneway)
        Replies the last node of this way, respecting or not its oneway state.
        Parameters:
        respectOneway - If true and if this way is a reversed oneway, replies the first node. Otherwise, replies the last node.
        Returns:
        the last node of this way, according to respectOneway and its oneway state.
        Since:
        5199
      • concernsArea

        public boolean concernsArea()
        Description copied from class: OsmPrimitive
        Determines if this primitive semantically concerns an area.
        Specified by:
        concernsArea in class OsmPrimitive
        Returns:
        true if this primitive semantically concerns an area, according to its type, geometry and tags, false otherwise.
      • keysChangedImpl

        protected void keysChangedImpl​(java.util.Map<java.lang.String,​java.lang.String> originalKeys)
        Description copied from class: AbstractPrimitive
        What to do, when the tags have changed by one of the tag-changing methods.
        Overrides:
        keysChangedImpl in class OsmPrimitive
        Parameters:
        originalKeys - original tags
      • getAngles

        public java.util.List<Pair<java.lang.Double,​Node>> getAngles()
        Returns angles of vertices.
        Returns:
        angles of the way
        Since:
        13670