public class PolygonGraphGenerator extends Object implements GraphGenerator
This graph generator takes Polygon objects as input when
constructing a graph. The following code constructs a graph from a set of polygons.
//get some polygons
Polygon[] polygons = ...
//determine what the relationship will be
PolygonGraphGenerator rel = new PolygonGraphGenerator.PolygonRelationship() {
public boolean related(Polygon p1, Polygon p2) {
return p1.intersects(p2);
}
public boolean equal(Polygon p1, Polygon p2) {
return p1.equals(p2);
}
}
//create the generator
PolygonGraphGenerator gg = new PolygonGraphGenerator(new BasicGraphBuilder(),rel);
//start building
for (int i = 0; i < polygons.length; i++) {
gg.add(polygons[i]);
}
For each distinct polygon added to the graph, a node is created. If two polygons are considered
equal, only a single node is created. If two polygons are considered related, the associated
nodes share an edge. Equality and relationship is determined by PolygonGraphGenerator.PolygonRelationship interface. An
instance of this interface is passed to the generator at construction.| Modifier and Type | Class and Description |
|---|---|
static interface |
PolygonGraphGenerator.PolygonRelationship
Determines the relationship among two polygons.
|
| Constructor and Description |
|---|
PolygonGraphGenerator(GraphBuilder builder,
PolygonGraphGenerator.PolygonRelationship rel) |
| Modifier and Type | Method and Description |
|---|---|
Graphable |
add(Object obj)
Adds an object to the graph.
|
protected Node |
find(Polygon polygon) |
Graphable |
get(Object obj)
Retrieves a component of the graph.
|
Graph |
getGraph()
Returns the graph being generated.
|
GraphBuilder |
getGraphBuilder()
Returns the underlying builder.
|
protected void |
relate(Node node) |
Graphable |
remove(Object obj)
Removes an object from the graph.
|
void |
setGraphBuilder(GraphBuilder builder)
Sets the underlying builder used to physically construct the graph.
|
public PolygonGraphGenerator(GraphBuilder builder, PolygonGraphGenerator.PolygonRelationship rel)
public Graphable add(Object obj)
GraphGeneratoradd in interface GraphGeneratorobj - The object to be modelled in the graph.public Graphable get(Object obj)
GraphGeneratorget in interface GraphGeneratorobj - The object modelled by the component.public Graphable remove(Object obj)
GraphGeneratorremove in interface GraphGeneratorobj - The object modelled by the component.public void setGraphBuilder(GraphBuilder builder)
GraphGeneratorsetGraphBuilder in interface GraphGeneratorbuilder - The new underlying GraphBuilder.public GraphBuilder getGraphBuilder()
GraphGeneratorgetGraphBuilder in interface GraphGeneratorpublic Graph getGraph()
GraphGeneratorgetGraph in interface GraphGeneratorprotected Node find(Polygon polygon)
protected void relate(Node node)
Copyright © 1996–2019 Geotools. All rights reserved.