Hi Jase, the first error you fixed properly, am XYNode will only be
created if you set a new GraphBuilder on the GraphGenerator via
GraphGenerator#setGraphBuilder.
For the second error, you need to cast to a LineString, instead of a
LineSegment. When a LineStringGraphGenerator is used to build a graph,
the edges correspond to LineString objects and the nodes corresond to
Point objects.
Hope that helps.
Justin
Jase wrote:
hi Justin,
I followed your instructions and am getting errors. Here is what I did.
XYNode src = (XYNode)lgb.getNode(new Coordinate (101.603802, 3.071856));
XYNode dest = (XYNode)lgb.getNode(new Coordinate(101.71339200,3.15235700));
Error : java.lang.ClassCastException:
org.geotools.graph.structure.basic.BasicNode
at test1.main(test1.java:86)
Line 86 refers to the first line above.
So I thought perhaps I should not have casted it and used this:-
Node src = lgb.getNode(new Coordinate (101.603802, 3.071856));
Node dest = lgb.getNode(new Coordinate(101.71339200,3.15235700));
and i got the following error:-
java.lang.ClassCastException
at test1$1.getWeight(test1.java:93)
at
org.geotools.graph.traverse.standard.DijkstraIterator.cont(DijkstraIterator.java:184)
at
org.geotools.graph.traverse.basic.BasicGraphTraversal.traverse(BasicGraphTraversal.java:172)
at
org.geotools.graph.path.DijkstraShortestPathFinder.calculate(DijkstraShortestPathFinder.java:85)
at test1.main(test1.java:102)
Line 93 : LineSegment line = (LineSegment)e.getObject(); (this is part
of the getWeight method)
Line 102: dsp.calculate();
I did some debugging on dst and src to see if there was a value and
there indeed was...
src=27895 while dst=6336
Thanks for helping me out with this.....
Jase
On 11/23/05, *Justin Deoliveira* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Hi Jase,
Looking closer at your code snippet I see the problem. You are creating
new nodes for src and dest. Instead the nodes need to be pre-existing in
the graph.
The LineStringGraphGenerator has a method called getNode(Coordinate).
You can use it to a node in the graph at a particular coordinate.
So instead of:
XYNode src = new BasicXYNode();
src.setCoordinate(new Coordinate (101.603802, 3.071856));
XYNode dest = new BasicXYNode();
dest.setCoordinate(new Coordinate(101.71339200,3.15235700));
You should use:
XYNode src = lgb.getNode(new Coordinate(101.603802, 3.071856));
XYNode dest = lgb.getNode(new Coordinate(101.71339200,3.15235700 ));
Hope that helps, let me know if that works for you.
Justin
Jase wrote:
> hi Justin,
>
> I'm not getting any errors. it's just that when i printed the
value of
> "p" i got a null value.
>
> Thanks
>
> Jase
>
> On 11/23/05, * Justin Deoliveira* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
> <mailto: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>>> wrote:
>
> Hi Jase,
>
> Could you send the stack trace of the exception. Thanks.
>
> Justin
>
> Jase wrote:
> > Hi Justin,
> >
> > Upon closer inspection on my database, I found that the roads
> have been
> > noded on the intersections. MOst of the roads I had a look
shares a
> > common end point.
> >
> > I proceeded on with using some of the algorithms that you
> suggested in
> > this mailing list. What I'm getting is a null pointer. I'm
a bit
> baffled
> > as to what might have gone wrong. I initially though that
the roads
> > might not have been noded so I tried with two points on
the same road
> > and got the same results.
> >
> > Attached are the codes that I used. I'm guessing I did
something
> wrong
> > at the "src" and "dest"
> >
> > Thanks.
> >
> > Jase
> >
> >
> >
> > DataStore pgDatastore =
> DataStoreFinder.getDataStore(params);
> > FeatureSource fsBC = pgDatastore.getFeatureSource
> ("mustmrr");
> > System.out.println("Road to be added: " +
> > fsBC.getCount(Query.ALL));
> > System.out.println("Reading PostGIS
datastore...");
> >
> > LineStringGraphGenerator lgb = new
> LineStringGraphGenerator();
> > //FeatureSource fs =
> (FeatureSource)layers.get("mustmrr");
> > FeatureResults fr = fsBC.getFeatures ();
> > FeatureCollection fc = fr.collection();
> > FeatureIterator feat = fc.features();
> >
> > Envelope envelope = fc.getBounds();
> > System.out.println ("Building graph network...");
> > while (feat.hasNext())
> > {
> > Feature ft = feat.next();
> >
> > if (envelope.contains(ft.getBounds ()))
> > {
> > System.out.println("Road Name:"+
> > ft.getAttribute("name").toString().trim() + "\tAtribute:"
> > +ft.getAttribute("wkb_geometry"));
> > lgb.add(ft.getAttribute("wkb_geometry"));
> >
> > }
> > }
> >
> > Graph g = lgb.getGraph();
> > System.out.println (g);
> > XYNode src = null;
> > src = new BasicXYNode();
> > src.setCoordinate(new Coordinate (101.603802,
3.071856));
> >
> > XYNode dest = new BasicXYNode();
> > dest.setCoordinate(new
> Coordinate(101.71339200,3.15235700));
> >
> > DijkstraIterator.EdgeWeighter weighter = new
> > DijkstraIterator.EdgeWeighter()
> > {
> > public double getWeight(Edge e)
> > {
> > LineSegment line =
(LineSegment)e.getObject();
> > return(line.getLength());
> >
> > }
> > };
> >
> > DijkstraShortestPathFinder dsp = new
> > DijkstraShortestPathFinder(g, src, weighter);
> > System.out.println("Calculating Paths....");
> > dsp.calculate();
> > Path p = dsp.getPath(dest);
> > System.out.println(p);
>
>
> --
> Justin Deoliveira
> The Open Planning Project
> http://topp.openplans.org
>
>
--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org
--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users