org.geotools.graph.build.polygon
Class PolygonGraphGenerator

java.lang.Object
  extended byorg.geotools.graph.build.polygon.PolygonGraphGenerator
All Implemented Interfaces:
GraphGenerator

public class PolygonGraphGenerator
extends java.lang.Object
implements GraphGenerator

An implementation of GraphGenerator used to build graphs from a set of polygons.

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.

Author:
Justin Deoliveira, The Open Planning Project

Nested Class Summary
static interface PolygonGraphGenerator.PolygonRelationship
          Determines the relationship among two polygons.
 
Constructor Summary
PolygonGraphGenerator(GraphBuilder builder, PolygonGraphGenerator.PolygonRelationship rel)
           
 
Method Summary
 Graphable add(java.lang.Object obj)
          Adds an object to the graph.
protected  Node find(com.vividsolutions.jts.geom.Polygon polygon)
           
 Graphable get(java.lang.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(java.lang.Object obj)
          Removes an object from the graph.
 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

PolygonGraphGenerator

public PolygonGraphGenerator(GraphBuilder builder,
                             PolygonGraphGenerator.PolygonRelationship rel)
Method Detail

add

public Graphable add(java.lang.Object obj)
Description copied from interface: GraphGenerator
Adds an object to the graph.

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

get

public Graphable get(java.lang.Object obj)
Description copied from interface: GraphGenerator
Retrieves a component of the graph.

Specified by:
get in interface GraphGenerator
Parameters:
obj - The object modelled by the component.
Returns:
The graph component used to model the object.

remove

public Graphable remove(java.lang.Object obj)
Description copied from interface: GraphGenerator
Removes an object from the graph.

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

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.

getGraphBuilder

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

Specified by:
getGraphBuilder in interface GraphGenerator
Returns:
The underyling builder.

getGraph

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

Specified by:
getGraph in interface GraphGenerator
Returns:
The generated graph.

find

protected Node find(com.vividsolutions.jts.geom.Polygon polygon)

relate

protected void relate(Node node)


Copyright © GeoTools. All Rights Reserved.