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]>> 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
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users