Class Way

All Implemented Interfaces:
Comparable<IPrimitive>, IQuadBucketType, IFilterablePrimitive, IPrimitive, IWay<Node>, PrimitiveId, Stylable, Tagged, TemplateEngineDataProvider

public final class Way extends OsmPrimitive implements IWay<Node>
One full way, consisting of a list of way nodes.
Since:
64
  • Field Details

  • Constructor Details

    • 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:
      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:
      IllegalArgumentException - if id < 0
      Since:
      2620
  • Method Details

    • getNodes

      public List<Node> getNodes()
      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(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 List<Node> removeDouble(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 List<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 Set<Node> getNeighbours(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 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.
    • accept

      public void accept(PrimitiveVisitor visitor)
      Description copied from interface: IPrimitive
      Makes the given visitor visit this primitive.
      Specified by:
      accept in interface IPrimitive
      Parameters:
      visitor - visitor
    • 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 String toString()
      Overrides:
      toString in class Object
    • hasEqualSemanticAttributes

      public boolean hasEqualSemanticAttributes(OsmPrimitive other, boolean testInterestingTagsOnly)
      Overrides:
      hasEqualSemanticAttributes in class OsmPrimitive
    • 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(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 List<Node> calculateRemoveNodes(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:
      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:
      IllegalStateException - if this way is marked as incomplete. We can't add a node to an incomplete way
      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:
    • lastNode

      public Node lastNode()
      Description copied from interface: IWay
      Returns the last node of this way. The result equals getNode(getNodesCount - 1).
      Specified by:
      lastNode in interface IWay<Node>
      Returns:
      the last node of this way
    • 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.
    • getType

      Description copied from interface: PrimitiveId
      Gets the type of object represented by this object. Note that this should return the base primitive type (OsmPrimitiveType.NODE, OsmPrimitiveType.WAY, and OsmPrimitiveType.RELATION).
      Specified by:
      getType in interface PrimitiveId
      Returns:
      the object type
      See Also:
    • getDisplayType

      Description copied from interface: IPrimitive
      Gets the type this primitive is displayed at
      Specified by:
      getDisplayType in interface IPrimitive
      Returns:
      A OsmPrimitiveType
    • checkNodes

      private void checkNodes()
    • fireNodesChanged

      private void fireNodesChanged()
    • 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, 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
    • setBBox

      private void setBBox(BBox bbox)
    • updatePosition

      public void updatePosition()
      Description copied from class: OsmPrimitive
      Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
      Specified by:
      updatePosition in class OsmPrimitive
    • 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
    • isUsable

      public boolean isUsable()
      Description copied from interface: IPrimitive
      Replies true, if the object is usable (i.e. complete and not deleted).
      Specified by:
      isUsable in interface IPrimitive
      Overrides:
      isUsable in class AbstractPrimitive
      Returns:
      true, if the object is usable.
      See Also:
    • 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
    • getLength

      public double getLength()
      Replies the length of the way, in metres, as computed by ILatLon.greatCircleDistance(org.openstreetmap.josm.data.coor.ILatLon).
      Returns:
      The length of the way, in metres
      Since:
      4138
    • getSegmentLengths

      public double[] getSegmentLengths()
      Replies the segment lengths of the way as computed by ILatLon.greatCircleDistance(org.openstreetmap.josm.data.coor.ILatLon).
      Returns:
      The segment lengths of a way in metres, following way direction
      Since:
      18553
    • getLongestSegmentLength

      public double getLongestSegmentLength()
      Replies the length of the longest segment of the way, in metres, as computed by ILatLon.greatCircleDistance(org.openstreetmap.josm.data.coor.ILatLon).
      Returns:
      The length of the segment, in metres
      Since:
      8320
    • 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.
    • isOutsideDownloadArea

      public boolean isOutsideDownloadArea()
      Description copied from class: OsmPrimitive
      Tests if this primitive lies outside of the downloaded area of its DataSet.
      Specified by:
      isOutsideDownloadArea in class OsmPrimitive
      Returns:
      true if this primitive lies outside of the downloaded area
    • keysChangedImpl

      protected void keysChangedImpl(Map<String,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
    • clearCachedNodeStyles

      public void clearCachedNodeStyles()
      Clears all cached styles for all nodes of this way. This should not be called from outside.
      See Also:
    • getAngles

      Returns angles of vertices.
      Returns:
      angles of the way
      Since:
      13670
    • getIdGenerator

      Description copied from class: AbstractPrimitive
      Returns the unique identifier generator.
      Specified by:
      getIdGenerator in class AbstractPrimitive
      Returns:
      the unique identifier generator