From: Jase <jas...@gm...> - 2005-11-23 10:43:33
|
hi Justin, I followed your instructions and am getting errors. Here is what I did. XYNode src =3D (XYNode)lgb.getNode(new Coordinate (101.603802, 3.071856)); XYNode dest =3D (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 =3D lgb.getNode(new Coordinate (101.603802, 3.071856)); Node dest =3D 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 =3D (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=3D27895 while dst=3D6336 Thanks for helping me out with this..... Jase On 11/23/05, Justin Deoliveira <jde...@un...> 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 =3D new BasicXYNode(); > src.setCoordinate(new Coordinate (101.603802, 3.071856)); > > XYNode dest =3D new BasicXYNode(); > dest.setCoordinate(new Coordinate(101.71339200,3.15235700)); > > You should use: > > XYNode src =3D lgb.getNode(new Coordinate(101.603802, 3.071856)); > XYNode dest =3D 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* <jde...@un... > > <mailto:jde...@un...>> 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 share= s > 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 =3D > > DataStoreFinder.getDataStore(params); > > > FeatureSource fsBC =3D pgDatastore.getFeatureSource > > ("mustmrr"); > > > System.out.println("Road to be added: " + > > > fsBC.getCount(Query.ALL)); > > > System.out.println("Reading PostGIS datastore..."); > > > > > > LineStringGraphGenerator lgb =3D new > > LineStringGraphGenerator(); > > > //FeatureSource fs =3D > > (FeatureSource)layers.get("mustmrr"); > > > FeatureResults fr =3D fsBC.getFeatures (); > > > FeatureCollection fc =3D fr.collection(); > > > FeatureIterator feat =3D fc.features(); > > > > > > Envelope envelope =3D fc.getBounds(); > > > System.out.println ("Building graph network..."); > > > while (feat.hasNext()) > > > { > > > Feature ft =3D 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 =3D lgb.getGraph(); > > > System.out.println (g); > > > XYNode src =3D null; > > > src =3D new BasicXYNode(); > > > src.setCoordinate(new Coordinate (101.603802, > 3.071856)); > > > > > > XYNode dest =3D new BasicXYNode(); > > > dest.setCoordinate(new > > Coordinate(101.71339200,3.15235700)); > > > > > > DijkstraIterator.EdgeWeighter weighter =3D new > > > DijkstraIterator.EdgeWeighter() > > > { > > > public double getWeight(Edge e) > > > { > > > LineSegment line =3D > (LineSegment)e.getObject(); > > > return(line.getLength()); > > > > > > } > > > }; > > > > > > DijkstraShortestPathFinder dsp =3D new > > > DijkstraShortestPathFinder(g, src, weighter); > > > System.out.println("Calculating Paths...."); > > > dsp.calculate(); > > > Path p =3D 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 > |