org.geotools.graph.build.line
Class OptLineGraphGenerator

java.lang.Object
  extended byorg.geotools.graph.build.line.OptLineGraphGenerator
All Implemented Interfaces:
GraphGenerator, LineGraphGenerator
Direct Known Subclasses:
OptDirectedLineGraphGenerator

public class OptLineGraphGenerator
extends java.lang.Object
implements LineGraphGenerator

An implementation of GraphGenerator used to generate an optimized graph representing a line network. Graphs are generated by supplying the generator with objects of type LineSegment via the add(Object) method.

For each line segment added, an edge in the graph is created. The builder records the end coordinates of each line added, and maintains a map of coordinates to nodes, creating nodes when neccessary.

Edges created by the generator are of type OptBasicEdge.
Nodes created by the generator are of type OptXYNode.

Since building optimized graphs requires knowing the degree of nodes before creating them, the physical construction of the graph is delayed until a call to generate() is made. No component is created with a call to add(Object), only information about the object is recorded.

Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
See Also:
OptEdge, OptXYNode

Constructor Summary
OptLineGraphGenerator()
          Constructs a new OptLineGraphGenerator.
 
Method Summary
 Graphable add(java.lang.Object obj)
          Adds a line to the graph.
 void generate()
          Performs the actual generation of the graph.
protected  Edge generateEdge(com.vividsolutions.jts.geom.LineSegment line)
           
protected  void generateEdges()
           
protected  void generateNodes()
           
 Graphable get(java.lang.Object obj)
          Returns the edge which represents a line.
 Edge getEdge(com.vividsolutions.jts.geom.Coordinate c1, com.vividsolutions.jts.geom.Coordinate c2)
           
 Graph getGraph()
          Returns the graph being generated.
 GraphBuilder getGraphBuilder()
          Returns the underlying builder.
protected  java.util.List getLines()
          Returns the lines added to the graph.
 Node getNode(com.vividsolutions.jts.geom.Coordinate c)
           
 java.util.Map getNodeMap()
          Returns the coordinate to node map.
 Graphable remove(java.lang.Object obj)
          Unsupported operation.
 void setGraphBuilder(GraphBuilder builder)
          Sets the underlying builder used to physically construct the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptLineGraphGenerator

public OptLineGraphGenerator()
Constructs a new OptLineGraphGenerator.

Method Detail

add

public Graphable add(java.lang.Object obj)
Adds a line to the graph. Note that this method returns null since actual building of the graph components is delayed until generate() is called.

Specified by:
add in interface GraphGenerator
Parameters:
obj - The object to be modelled in the graph.
Returns:
null

get

public Graphable get(java.lang.Object obj)
Returns the edge which represents a line. This method must be called after the call to generate(). Note that if the exact same line has been added to the graph multiple times, then only one of the edges that represents it will be returned. It is undefined which edge will be returned.

Specified by:
get in interface GraphGenerator
Parameters:
obj - An instance of LineSegment.
Returns:
Edge that represents the line.
See Also:
GraphGenerator.get(Object)

remove

public Graphable remove(java.lang.Object obj)
Unsupported operation.

Specified by:
remove in interface GraphGenerator
Parameters:
obj - The object modelled by the component.
Returns:
The graph component used to model the object.
Throws:
java.lang.UnsupportedOperationException

setGraphBuilder

public void setGraphBuilder(GraphBuilder builder)
Description copied from interface: GraphGenerator
Sets the underlying builder used to physically construct the graph.

Specified by:
setGraphBuilder in interface GraphGenerator
Parameters:
builder - The new underlying GraphBuilder.
See Also:
GraphGenerator.setGraphBuilder(GraphBuilder)

getGraphBuilder

public GraphBuilder getGraphBuilder()
Description copied from interface: GraphGenerator
Returns the underlying builder.

Specified by:
getGraphBuilder in interface GraphGenerator
Returns:
The underyling builder.
See Also:
GraphGenerator.getGraphBuilder()

getGraph

public Graph getGraph()
Description copied from interface: GraphGenerator
Returns the graph being generated.

Specified by:
getGraph in interface GraphGenerator
Returns:
The generated graph.
See Also:
GraphGenerator.getGraph()

generate

public void generate()
Performs the actual generation of the graph.


getNodeMap

public java.util.Map getNodeMap()
Returns the coordinate to node map. Note that before the call to generate the map does not contain any nodes.

Returns:
Coordinate to node map.

getLines

protected java.util.List getLines()
Returns the lines added to the graph.

Returns:
A list of LineSegment objects.

generateNodes

protected void generateNodes()

generateEdges

protected void generateEdges()

generateEdge

protected Edge generateEdge(com.vividsolutions.jts.geom.LineSegment line)

getNode

public Node getNode(com.vividsolutions.jts.geom.Coordinate c)
Specified by:
getNode in interface LineGraphGenerator

getEdge

public Edge getEdge(com.vividsolutions.jts.geom.Coordinate c1,
                    com.vividsolutions.jts.geom.Coordinate c2)
Specified by:
getEdge in interface LineGraphGenerator


Copyright © GeoTools. All Rights Reserved.