Class BaseGraph

java.lang.Object
com.graphhopper.storage.BaseGraph
All Implemented Interfaces:
Graph, Closeable, AutoCloseable

public class BaseGraph extends Object implements Graph, Closeable
The base graph handles nodes and edges file format. It can be used with different Directory implementations like RAMDirectory for fast access or via MMapDirectory for virtual-memory and not thread safe usage.

Note: A RAM DataAccess Object is thread-safe in itself but if used in this Graph implementation it is not write thread safe.

Life cycle: (1) object creation, (2) configuration via setters & getters, (3) create or loadExisting, (4) usage, (5) flush, (6) close

  • Constructor Details

    • BaseGraph

      public BaseGraph(Directory dir, int intsForFlags, boolean withElevation, boolean withTurnCosts, int segmentSize)
  • Method Details

    • debugPrint

      public void debugPrint()
    • getBaseGraph

      public BaseGraph getBaseGraph()
      Specified by:
      getBaseGraph in interface Graph
      Returns:
      a graph which behaves like an unprepared graph and e.g. the normal unidirectional Dijkstra or any graph traversal algorithm can be executed.
    • isInitialized

      public boolean isInitialized()
    • getNodes

      public int getNodes()
      Specified by:
      getNodes in interface Graph
      Returns:
      the number of created locations - via setNode() or edge()
    • getEdges

      public int getEdges()
      Specified by:
      getEdges in interface Graph
      Returns:
      the number of edges in this graph. Equivalent to getAllEdges().length().
    • getNodeAccess

      public NodeAccess getNodeAccess()
      Description copied from interface: Graph
      Creates an object to access node properties.
      Specified by:
      getNodeAccess in interface Graph
    • getBounds

      public BBox getBounds()
      Description copied from interface: Graph
      Returns the implicit bounds of this graph calculated from the lat,lon input of setNode
      Specified by:
      getBounds in interface Graph
    • freeze

      public void freeze()
    • isFrozen

      public boolean isFrozen()
    • create

      public BaseGraph create(long initSize)
    • getIntsForFlags

      public int getIntsForFlags()
    • toDetailsString

      public String toDetailsString()
    • flushAndCloseGeometryAndNameStorage

      public void flushAndCloseGeometryAndNameStorage()
      Flush and free resources that are not needed for post-processing (way geometries and KVStorage for edges).
    • flush

      public void flush()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getCapacity

      public long getCapacity()
    • loadExisting

      public boolean loadExisting()
    • edge

      public EdgeIteratorState edge(int nodeA, int nodeB)
      Create edge between nodes a and b
      Specified by:
      edge in interface Graph
      Parameters:
      nodeA - the index of the starting (tower) node of the edge
      nodeB - the index of the ending (tower) node of the edge
      Returns:
      EdgeIteratorState of newly created edge
    • getEdgeIteratorState

      public EdgeIteratorState getEdgeIteratorState(int edgeId, int adjNode)
      Description copied from interface: Graph
      Returns a wrapper over the specified edgeId.
      Specified by:
      getEdgeIteratorState in interface Graph
      adjNode - is the node that will be returned via getAdjNode(). If adjNode is Integer.MIN_VALUE then the edge will be returned in the direction of how it is stored
      Returns:
      a new EdgeIteratorState object or potentially null if adjNode does not match
    • getEdgeIteratorStateForKey

      public EdgeIteratorState getEdgeIteratorStateForKey(int edgeKey)
      Description copied from interface: Graph
      Returns the edge state for the given edge key
      Specified by:
      getEdgeIteratorStateForKey in interface Graph
      See Also:
    • createEdgeExplorer

      public EdgeExplorer createEdgeExplorer(EdgeFilter filter)
      Description copied from interface: Graph
      Returns an EdgeExplorer which makes it possible to traverse all filtered edges of a specific node. Calling this method might be expensive, so e.g. create an explorer before a for loop!
      Specified by:
      createEdgeExplorer in interface Graph
    • createEdgeExplorer

      public EdgeExplorer createEdgeExplorer()
      Description copied from interface: Graph
      Creates an EdgeExplorer that accepts all edges
      Specified by:
      createEdgeExplorer in interface Graph
      See Also:
    • getAllEdges

      public AllEdgesIterator getAllEdges()
      Specified by:
      getAllEdges in interface Graph
      Returns:
      all edges in this graph, where baseNode will be the smaller node.
    • getTurnCostStorage

      public TurnCostStorage getTurnCostStorage()
      Specified by:
      getTurnCostStorage in interface Graph
      Returns:
      the TurnCostStorage or null if not supported
    • wrapWeighting

      public Weighting wrapWeighting(Weighting weighting)
      Description copied from interface: Graph
      Wraps the given weighting into a weighting that can be used by this graph
      Specified by:
      wrapWeighting in interface Graph
    • getOtherNode

      public int getOtherNode(int edge, int node)
      Specified by:
      getOtherNode in interface Graph
      Returns:
      the 'opposite' node of a given edge, so if there is an edge 3-2 and node =2 this returns 3
    • isAdjacentToNode

      public boolean isAdjacentToNode(int edge, int node)
      Specified by:
      isAdjacentToNode in interface Graph
      Returns:
      true if the edge with id edge is adjacent to node, false otherwise
    • createEdgeIntAccess

      public EdgeIntAccess createEdgeIntAccess()
    • isClosed

      public boolean isClosed()
    • getDirectory

      public Directory getDirectory()
    • getSegmentSize

      public int getSegmentSize()