## geotools-gt2-users

 [Geotools-gt2-users] problem with building graph From: mil84 - 2011-05-20 16:32:43 ```Hi, i would like to do app "shortest path finder", so I read something about Graph, and on the beginning I was pleased because it looked very easy :) So I tried very simple example like this: GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); LineStringGraphGenerator lineStringGen = new LineStringGraphGenerator(); Point a = geometryFactory.createPoint(new Coordinate(0, 0)); Point b = geometryFactory.createPoint(new Coordinate(1, 0)); Point c = geometryFactory.createPoint(new Coordinate(1, 1)); Point d = geometryFactory.createPoint(new Coordinate(0, 1)); LineString abcd = geometryFactory.createLineString(new Coordinate[] { new Coordinate(a.getX(), a.getY()), new Coordinate(b.getX(), b.getY()), new Coordinate(c.getX(), c.getY()), new Coordinate(d.getX(), d.getY()) }); LineString ac = geometryFactory.createLineString(new Coordinate[] { new Coordinate(a.getX(), a.getY()), new Coordinate(c.getX(), c.getY()) }); lineStringGen.add(abcd); lineStringGen.add(ac); Graph g = lineStringGen.getGraph(); as u can see, I tried to create just very simple graph with 4 points A,B,C,D and lines between them like this: http://osgeo-org.1803224.n2.nabble.com/file/n6386745/graph.jpg But when i build graph, and use method getNodes(), i have only three nodes (why? i build graph with 4) also edges are different. So of course, when I use DijkstraShortestPathFinder, it also gives me different result. What did I wrong? -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/problem-with-building-graph-tp6386745p6386745.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ```
 Re: [Geotools-gt2-users] problem with building graph From: Michael Bedward - 2011-05-21 09:37:39 ```Hello, I'm not very familiar with the graph module, but I think your example will work if done like this: GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); Coordinate a = new Coordinate(0, 0); Coordinate b = new Coordinate(1, 0); Coordinate c = new Coordinate(1, 1); Coordinate d = new Coordinate(0, 1); LineString ab = gf.createLineString(new Coordinate[]{a, b}); LineString bc = gf.createLineString(new Coordinate[]{b, c}); LineString cd = gf.createLineString(new Coordinate[]{c, d}); LineString ac = gf.createLineString(new Coordinate[]{a, c}); LineStringGraphGenerator gen = new LineStringGraphGenerator(); gen.add(ab); gen.add(bc); gen.add(cd); gen.add(ac); Graph graph = gen.getGraph(); I know that there are other list members who use the graph module regularly so perhaps one of them can correct me if I'm wrong or give you more hints. Michael On 21 May 2011 02:32, mil84 wrote: > Hi, i would like to do app "shortest path finder", so I read something about > Graph, and on the beginning I was pleased because it looked very easy :) So > I tried very simple example like this: > > > GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); > LineStringGraphGenerator lineStringGen = new LineStringGraphGenerator(); > > Point a = geometryFactory.createPoint(new Coordinate(0, 0)); > Point b = geometryFactory.createPoint(new Coordinate(1, 0)); > Point c = geometryFactory.createPoint(new Coordinate(1, 1)); > Point d = geometryFactory.createPoint(new Coordinate(0, 1)); > > LineString abcd = geometryFactory.createLineString(new Coordinate[] { >                new Coordinate(a.getX(), a.getY()), new Coordinate(b.getX(), b.getY()), >                new Coordinate(c.getX(), c.getY()), new Coordinate(d.getX(), d.getY()) }); > > LineString ac = geometryFactory.createLineString(new Coordinate[] { >                new Coordinate(a.getX(), a.getY()), new Coordinate(c.getX(), c.getY()) }); > > lineStringGen.add(abcd); > lineStringGen.add(ac); > Graph g = lineStringGen.getGraph(); > > > as u can see, I tried to create just very simple graph with 4 points A,B,C,D > and lines between them like this: > > http://osgeo-org.1803224.n2.nabble.com/file/n6386745/graph.jpg > > But when i build graph, and use method getNodes(), i have only three nodes > (why? i build graph with 4) also edges are different. So of course, when I > use DijkstraShortestPathFinder, it also gives me different result. > > What did I wrong? > > -- > View this message in context: http://osgeo-org.1803224.n2.nabble.com/problem-with-building-graph-tp6386745p6386745.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > What Every C/C++ and Fortran developer Should Know! > Read this article and learn how Intel has extended the reach of its > next-generation tools to help Windows* and Linux* C/C++ and Fortran > developers boost performance applications - including clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > ```
 Re: [Geotools-gt2-users] problem with building graph From: PaulCrease - 2011-05-23 13:32:26 ```Hi, That is interesting, i think using your code example would mean that only the start node and end node of line abcd would overlap with the start point of line ac, therefore giving three nodes when the graph is built, but I am not 100% on that. If I am right then the example below should also work and return 4 nodes :- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); LineStringGraphGenerator lineStringGen = new LineStringGraphGenerator(); Point a = geometryFactory.createPoint(new Coordinate(0, 0)); Point b = geometryFactory.createPoint(new Coordinate(1, 0)); Point c = geometryFactory.createPoint(new Coordinate(1, 1)); Point d = geometryFactory.createPoint(new Coordinate(0, 1)); LineString abc = geometryFactory.createLineString(new Coordinate[] { new Coordinate(a.getX(), a.getY()), new Coordinate(b.getX(), b.getY()), new Coordinate(c.getX(), c.getY()) }); LineString adc = geometryFactory.createLineString(new Coordinate[] { new Coordinate(a.getX(), a.getY()), new Coordinate(d.getX(), d.getY()), new Coordinate(c.getX(), c.getY()) }); LineString ac = geometryFactory.createLineString(new Coordinate[] { new Coordinate(a.getX(), a.getY()), new Coordinate(c.getX(), c.getY()) }); lineStringGen.add(abc); lineStringGen.add(adc); lineStringGen.add(ac); Graph g = lineStringGen.getGraph(); Additionally, from personal experience when you start applying the Graph library to real network datasets the fun really begins.... :-) Kind Regards, Paul. -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/problem-with-building-graph-tp6386745p6394466.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ```