Package org.geotools.graph.build.line
Class BasicLineGraphGenerator
- Object
-
- BasicLineGraphGenerator
-
- All Implemented Interfaces:
GraphGenerator,LineGraphGenerator
- Direct Known Subclasses:
BasicDirectedLineGraphGenerator,LineStringGraphGenerator
public class BasicLineGraphGenerator extends Object implements LineGraphGenerator
An implementation of GraphGenerator used to generate a 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.
If a tolerance distance is set, the end coordinates matched to nodes with a tolerance distance (using a spatial index).
Edges created by the generator are of type BasicEdge and contain an object of type LineSegment.
Nodes created by the generator are of type BasicXYNode and contain an object of type Coordinate.- Author:
- Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net, Anders Bakkevold, Bouvet AS, bakkedev@gmail.com
- See Also:
BasicXYNode,BasicEdge,LineSegment,Coordinate
-
-
Constructor Summary
Constructors Constructor Description BasicLineGraphGenerator()Constructs a new BasicLineGraphGenerator.BasicLineGraphGenerator(double tolerance)Constructs a new BasicLineGraphGenerator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Graphableadd(Object obj)Adds a line to the graph.protected LineSegmentalterLine(LineSegment line, Node n1, Node n2)Graphableget(Object obj)Returns the edge which represents a line.EdgegetEdge(Coordinate c1, Coordinate c2)Retrieve edge between the two coordinates.GraphgetGraph()Returns the graph being generated.GraphBuildergetGraphBuilder()Returns the underlying builder.NodegetNode(Coordinate c)Look up a Node for the provided coordinate.MapgetNodeMap()Returns the coordinate to node map used to build nodes representing line endpoint coordinates.Graphableremove(Object obj)Removes the edge from the graph that represents a line.voidsetGraphBuilder(GraphBuilder builder)Sets the underlying builder used to physically construct the graph.protected voidsetObject(Edge e, Object obj)protected voidsetObject(Node n, Object obj)protected booleanuseTolerance()
-
-
-
Constructor Detail
-
BasicLineGraphGenerator
public BasicLineGraphGenerator()
Constructs a new BasicLineGraphGenerator.Tolerance is 0.0 as default, meaning coordinates must be equal for lines to connect at a node.
-
BasicLineGraphGenerator
public BasicLineGraphGenerator(double tolerance)
Constructs a new BasicLineGraphGenerator.If two coordinates are considered equal (and should be snapped to the same Node), the distance between them must be less than the tolerance value.
- Parameters:
tolerance- threshold distance value for coordinates to be considered equal
-
-
Method Detail
-
add
public Graphable add(Object obj)
Adds a line to the graph.- Specified by:
addin interfaceGraphGenerator- Parameters:
obj- An instance of LineSegment.- Returns:
- A BasicEdge.
- See Also:
LineSegment,GraphGenerator.add(Object)
-
alterLine
protected LineSegment alterLine(LineSegment line, Node n1, Node n2)
-
get
public Graphable get(Object obj)
Returns the edge which represents a line. 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:
getin interfaceGraphGenerator- Parameters:
obj- An instance of LineSegment.- Returns:
- Edge that represents the line.
- See Also:
GraphGenerator.get(Object)
-
remove
public Graphable remove(Object obj)
Removes the edge from the graph that represents a line.- Specified by:
removein interfaceGraphGenerator- Parameters:
obj- The object modelled by the component.- Returns:
- Edge that represents the line.
- See Also:
GraphGenerator.remove(Object)
-
setGraphBuilder
public void setGraphBuilder(GraphBuilder builder)
Description copied from interface:GraphGeneratorSets the underlying builder used to physically construct the graph.- Specified by:
setGraphBuilderin interfaceGraphGenerator- Parameters:
builder- The new underlying GraphBuilder.- See Also:
GraphGenerator.setGraphBuilder(GraphBuilder)
-
getGraphBuilder
public GraphBuilder getGraphBuilder()
Description copied from interface:GraphGeneratorReturns the underlying builder.- Specified by:
getGraphBuilderin interfaceGraphGenerator- Returns:
- The underyling builder.
- See Also:
GraphGenerator.getGraphBuilder()
-
getGraph
public Graph getGraph()
Description copied from interface:GraphGeneratorReturns the graph being generated.- Specified by:
getGraphin interfaceGraphGenerator- Returns:
- The generated graph.
- See Also:
GraphGenerator.getGraph()
-
getNodeMap
public Map getNodeMap()
Returns the coordinate to node map used to build nodes representing line endpoint coordinates.- Returns:
- coordinate to node map.
-
getNode
public Node getNode(Coordinate c)
Description copied from interface:LineGraphGeneratorLook up a Node for the provided coordinate.- Specified by:
getNodein interfaceLineGraphGenerator- Returns:
- Node
-
getEdge
public Edge getEdge(Coordinate c1, Coordinate c2)
Description copied from interface:LineGraphGeneratorRetrieve edge between the two coordinates.- Specified by:
getEdgein interfaceLineGraphGenerator- Returns:
- Edge
-
useTolerance
protected boolean useTolerance()
-
-