|
From: Suneet K. <sun...@ho...> - 2005-07-01 03:31:34
|
Hi.
I've been trying to get the Graph Traversal algorithm to work with a =
shapefile of a road network. This is my first experience with GeoTools =
and have quite a few questions.
The graph examples in the tutorials do not work with the 2.1.M4 version =
of GeoTools.
So i tried to modify the example code but was not very successful. Here =
is the code and some output
1. the conversion of Multilinestring to Linestring.
FeatureCollection fc =3D featureSource.getFeatures().collection();
LineStringGraphGenerator lgb =3D new LineStringGraphGenerator();
FeatureIterator f =3D fc.features();
while (f.hasNext()) {
Feature feature =3D f.next();
GeometryCollectionIterator gci =3D new =
GeometryCollectionIterator((GeometryCollection) =
feature.getDefaultGeometry());
gci.next(); // since the first iterator element is the original =
MULTILINESTRING feature itself
while (gci.hasNext()) {
Geometry geo =3D (Geometry) gci.next();
System.out.println("\t" + geo);
lgb.add(geo);
}
}
Graph g =3D lgb.getGraph();
Partial Output :=20
MULTILINESTRING ((324939 672627, 324944 672561, 324899 672481))
LINESTRING (324939 672627, 324944 672561, 324899 672481)
Is it possible to modify the codebase to accept MultiLineString's while =
building the as well (although I am not sure of how to go about doing =
this). I found several users having similar problems having to deal with =
conversion of MULTILINESTRING TO LINESTRING.
2. The Graph Traversal code
Graph g =3D lgb.getGraph();
System.out.println(g);
class PrintVisitor implements GraphVisitor {
public int visit(Graphable element) {
System.out.println(element);
return GraphTraversal.CONTINUE;
}
}
PrintVisitor pv =3D new PrintVisitor();
SimpleGraphWalker sgv =3D new SimpleGraphWalker(pv);
BasicGraphTraversal bgt =3D new BasicGraphTraversal(g, sgv,
new BreadthFirstIterator());
bgt.traverse(); //I get a java.lang.NullPointerException here
Partial Output :=20
V=3D[103, 355, 661, 334, 219, 296,............
E=3D[746 (678,700), 92 (90,91), 19...........
Based on the two outputs shown I was wondering how the graphs get built =
as there seems to be completely different values than the =
Multilinestrings values when comparing the two outputs, assuming that =
the code works as I expect it to.
What I would like to be able to do is take a ShapeFile road network and =
have a graph structure in memory that can be acessed easily. I would =
also like to experiment with weights/cost functions and traversal =
algorithms. I have seen some mails in the lists referring to code being =
mailed by Marc Andre and Justin but these were mailed as attachments and =
are not accessible in the mailing lists.=20
Another problem is that I tried working the same examples with the =
GeoTools 2.1.RC1 before trying it with 2.1.M4 and noticed that the API's =
are constantly eveolving. In that case I feel I should be using the =
latest version to ensure not having to rewrite code. Is there anyone who =
has worked the graph examples with the latest version. (Was also =
wondering why some of the class method calls in 2.1.RC1 return Object.
Lastly I noticed some demo code and a report of which demos failed. Is =
it possible to start including the graph demos as part of the build. =
Also is the only way to get API documentation for versions like the =
2.1.M5 by building from the source.
This is work towards a Master's thesis. Any help and example code would =
be greatly appreciated in the area of graph traversal, shortest path =
algorithms and cost functions.=20
Thanks in advance
Suneet Kamath
|