Class OSMNetwork

  • All Implemented Interfaces:
    java.io.Serializable

    public class OSMNetwork
    extends java.lang.Object
    implements java.io.Serializable
    Container for all imported entities of an OpenStreetMap file.

    Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $, initial version 31 dec. 2014

    Author:
    Moritz Bergmann
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      OSMNetwork​(java.lang.String name)
      Construct a new OSMNetwork.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNode​(OSMNode node)
      Add one OSMNode to this OSMNetwork.
      void addRelation​(OSMRelation osmRelation)
      Add one OSMRelation to this Network.
      void addWay​(OSMWay way)
      Add one OSMWay to this OSMNetwork.
      OSMLink findFollowingLink​(OSMLink link)
      Finds the link that follows a given OSMLink.
      OSMLink findPrecedingLink​(OSMLink link)
      Finds an OSMLink that precedes the given OSMLink.
      java.util.List<OSMLink> getLinks()
      Retrieve the list of OSMLinks of this OSMNetwork.
      java.lang.String getName()
      Retrieve the name of this OSMNetwork.
      OSMNode getNode​(long nodeId)
      Retrieve a Node from this Network.
      java.util.Map<java.lang.Long,​OSMNode> getNodes()
      Retrieve the map of OSMNode ids to OSMNodes of this OSMNetwork.
      java.util.List<java.lang.Long> getNodesFromWay​(java.lang.Long wayId)
      Retrieve a list of Nodes that form a Way from this Network.
      OSMRelation getRelation​(long relid)
      Retrieve a Relation from this Network.
      java.util.Map<java.lang.Long,​OSMRelation> getRelations()
      Retrieve the map of OSMRelations of this OSMNetwork.
      OSMWay getWay​(long wayid)
      Retrieve a Way from this Network.
      java.util.Map<java.lang.Long,​OSMWay> getWays()
      Retrieve the map of OSMWays of this OSMNetwork.
      boolean hasFollowingLink​(OSMLink link)
      Returns true if the given OSMLink has a following OSMLink.
      boolean hasPrecedingLink​(OSMLink link)
      Returns true if the given link has a preceding link.
      void makeLinks​(WarningListener warningListener, ProgressListener progressListener)
      Creates links out of the ways in this network.
      void removeRedundancy()
      FIXME Network looks 'crooked' after using this.
      void setNodes​(java.util.LinkedHashMap<java.lang.Long,​OSMNode> newnodes)
      Set/replace the Nodes of this Network.
      The provided list is not copied; the caller should not modify the list after setting it.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • OSMNetwork

        public OSMNetwork​(java.lang.String name)
        Construct a new OSMNetwork.
        Parameters:
        name - String; the name of the new Network
    • Method Detail

      • getNodesFromWay

        public final java.util.List<java.lang.Long> getNodesFromWay​(java.lang.Long wayId)
                                                             throws java.io.IOException
        Retrieve a list of Nodes that form a Way from this Network.
        Parameters:
        wayId - Long; the id of the Way
        Returns:
        List<Long>; the list of OSMNode ids of the OSMWay with the specified id
        Throws:
        java.io.IOException - when no Way with the specified id exists in this Network
      • getNode

        public final OSMNode getNode​(long nodeId)
                              throws java.io.IOException
        Retrieve a Node from this Network.
        Parameters:
        nodeId - long; the id of the Node
        Returns:
        node OSMNode; the node with the specified id
        Throws:
        java.io.IOException - when no OSMNode with the specified id exist in this Network
      • getNodes

        public final java.util.Map<java.lang.Long,​OSMNode> getNodes()
        Retrieve the map of OSMNode ids to OSMNodes of this OSMNetwork.
        Returns:
        Map<Long, OSMNode>; the map of all Nodes in this Network (modifications of the returned object are reflected in this OSMNetwork)
      • getRelation

        public final OSMRelation getRelation​(long relid)
                                      throws java.io.IOException
        Retrieve a Relation from this Network.
        Parameters:
        relid - long; the id of the Relation
        Returns:
        OSMRelation; modifications of the result are reflected in this OSMNetwork
        Throws:
        java.io.IOException - when no Relation with the specified id exists in this Network
      • getRelations

        public final java.util.Map<java.lang.Long,​OSMRelation> getRelations()
        Retrieve the map of OSMRelations of this OSMNetwork.
        Returns:
        Map<Long, OSMRelation>; the map of all OSMRelations in the network (modifications of the returned object are reflected in this OSMNetwork)
      • getWay

        public final OSMWay getWay​(long wayid)
                            throws java.io.IOException
        Retrieve a Way from this Network.
        Parameters:
        wayid - long; the id of a Way
        Returns:
        Way
        Throws:
        java.io.IOException - when no Way with the specified id exist in this network
      • getName

        public final java.lang.String getName()
        Retrieve the name of this OSMNetwork.
        Returns:
        name String; the name of this OSMNetwork
      • setNodes

        public final void setNodes​(java.util.LinkedHashMap<java.lang.Long,​OSMNode> newnodes)
        Set/replace the Nodes of this Network.
        The provided list is not copied; the caller should not modify the list after setting it.
        Parameters:
        newnodes - LinkedHashMap<Long, OSMNode>; the (new) Nodes for this Network
      • addNode

        public final void addNode​(OSMNode node)
        Add one OSMNode to this OSMNetwork.
        Parameters:
        node - OSMNode; the node to add to this OSMNetwork
      • addWay

        public final void addWay​(OSMWay way)
        Add one OSMWay to this OSMNetwork.
        Parameters:
        way - OSMWay; the OSMWay to add
      • addRelation

        public final void addRelation​(OSMRelation osmRelation)
        Add one OSMRelation to this Network.
        Parameters:
        osmRelation - OSMRelation; the OSMRelation to add
      • getWays

        public final java.util.Map<java.lang.Long,​OSMWay> getWays()
        Retrieve the map of OSMWays of this OSMNetwork.
        Returns:
        ways Map<Long, OSMWay>; the map of OSMWays of this OSMNetwork; modifications of the result are reflected in this OSMNetwork
      • getLinks

        public final java.util.List<OSMLink> getLinks()
        Retrieve the list of OSMLinks of this OSMNetwork.
        Returns:
        links List<OSMLink>; the list of OSMLinks of this OSMNetwork; modifications of the result are reflected in this OSMNetwork
      • makeLinks

        public final void makeLinks​(WarningListener warningListener,
                                    ProgressListener progressListener)
                             throws java.io.IOException
        Creates links out of the ways in this network.
        Parameters:
        warningListener - WarningListener; the warning listener that will receive warning events
        progressListener - ProgressListener; the progress listener that will receive progress events
        Throws:
        java.io.IOException - on read errors
      • removeRedundancy

        public final void removeRedundancy()
        FIXME Network looks 'crooked' after using this. This function checks for and removes redundancies between the networks links.
      • findFollowingLink

        public final OSMLink findFollowingLink​(OSMLink link)
        Finds the link that follows a given OSMLink.
        Parameters:
        link - OSMLink; OSMLink for which a successor OSMLink is sought
        Returns:
        OSMLink (one of) the successor OSMLink(s) of the given OSMLink, or null if the given OSMLink has no successors
      • findPrecedingLink

        public final OSMLink findPrecedingLink​(OSMLink link)
        Finds an OSMLink that precedes the given OSMLink.
        Parameters:
        link - OSMLink; the OSMLink for which a predecessor OSMLink is sought
        Returns:
        OSMLink (one of) the predecessor OSMLink(s) of the given OSMLink, or null if the given OSMLink has no predecessors
      • hasPrecedingLink

        public final boolean hasPrecedingLink​(OSMLink link)
        Returns true if the given link has a preceding link.
        Parameters:
        link - OSMLink; the link for which the caller wants to know whether there is a preceding link
        Returns:
        boolean; true if the given link has one or more predecessors; false otherwise
      • hasFollowingLink

        public final boolean hasFollowingLink​(OSMLink link)
        Returns true if the given OSMLink has a following OSMLink.
        Parameters:
        link - OSMLink; the OSMLink for which the caller wants to know if it has a follower OSMLink
        Returns:
        boolean; true if the specified OSMLink has a follower link in this OSMNetwork
      • toString

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