/// <summary>
        /// Uses the passed geometry collection to generate a QuickGraph.
        /// </summary>
        /// <param name="edges"></param>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        public ILineString TestGraphBuilder2WithSampleGeometries(IGeometryCollection edges, ICoordinate src, ICoordinate dst)
        {
            GraphBuilder2 builder = new GraphBuilder2(true);            
            foreach (IMultiLineString edge in edges.Geometries)
                foreach (ILineString line in edge.Geometries)                                
                    builder.Add(line);            
            builder.Initialize();

            return builder.Perform(src, dst);
        }
        public void BuildGraphFromStradeShapefile()
        {
            string shapepath = "strade_fixed.shp";
            int count = 703;

            Assert.IsTrue(File.Exists(shapepath));
            ShapefileReader reader = new ShapefileReader(shapepath);
            IGeometryCollection edges = reader.ReadAll();
            Assert.IsNotNull(edges);
            Assert.IsInstanceOfType(typeof(GeometryCollection), edges);
            Assert.AreEqual(count, edges.NumGeometries);

            ICoordinate startCoord = new Coordinate(2317300d, 4843961d);
            ICoordinate endCoord = new Coordinate(2322739d, 4844539d);

            bool startFound = false;
            bool endFound = false;            
            GraphBuilder2 builder = new GraphBuilder2(true);
            foreach (IMultiLineString mlstr in edges.Geometries)
            {
                Assert.AreEqual(1, mlstr.NumGeometries);
                ILineString str = mlstr.GetGeometryN(0) as ILineString;
                Assert.IsNotNull(str);
                Assert.IsTrue(builder.Add(str));

                if (!startFound)
                {
                    List<ICoordinate> coords = new List<ICoordinate>(str.Coordinates);
                    if (coords.Contains(startCoord))
                        startFound = true;
                }

                if (!endFound)
                {
                    List<ICoordinate> coords = new List<ICoordinate>(str.Coordinates);
                    if (coords.Contains(endCoord))
                        endFound = true;
                }
            }
            builder.Initialize();
            Assert.IsTrue(startFound);
            Assert.IsTrue(endFound);

            ILineString path = builder.Perform(startCoord, endCoord);
            Assert.IsNotNull(path);
            SaveGraphResult(path);

            ILineString reverse = builder.Perform(startCoord, endCoord);
            Assert.IsNotNull(reverse);
            Assert.AreEqual(path, reverse.Reverse());
        }
        public void BuildGraphFromMinimalGraphShapefile()
        {
            string shapepath = "minimalgraph.shp";
            int count = 15;

            Assert.IsTrue(File.Exists(shapepath));
            ShapefileReader reader = new ShapefileReader(shapepath);
            IGeometryCollection edges = reader.ReadAll();
            Assert.IsNotNull(edges);
            Assert.IsInstanceOfType(typeof(GeometryCollection), edges);
            Assert.AreEqual(count, edges.NumGeometries);

            ILineString startls = edges.GetGeometryN(0).GetGeometryN(0) as ILineString;
            Assert.IsNotNull(startls);
            ILineString endls = edges.GetGeometryN(5).GetGeometryN(0) as ILineString; ;
            Assert.IsNotNull(endls);

            GraphBuilder2 builder = new GraphBuilder2(true);
            foreach (IMultiLineString mlstr in edges.Geometries)
            {
                Assert.AreEqual(1, mlstr.NumGeometries);
                ILineString str = mlstr.GetGeometryN(0) as ILineString;
                Assert.IsNotNull(str);
                Assert.IsTrue(builder.Add(str));
            }
            builder.Initialize();
            
            ILineString path = builder.Perform(startls.StartPoint, endls.EndPoint);
            Assert.IsNotNull(path);
        }
        public void BuildGraphFromCompleteGraphShapefile()
        {
            string shapepath = "graph.shp";
            int count = 1179;

            Assert.IsTrue(File.Exists(shapepath));
            ShapefileReader reader = new ShapefileReader(shapepath);
            IGeometryCollection edges = reader.ReadAll();
            Assert.IsNotNull(edges);
            Assert.IsInstanceOfType(typeof(GeometryCollection), edges);
            Assert.AreEqual(count, edges.NumGeometries);

            ILineString startls = edges.GetGeometryN(515).GetGeometryN(0) as ILineString;
            Assert.IsNotNull(startls);
            IPoint startPoint = startls.EndPoint;
            Assert.AreEqual(2317300d, startPoint.X);
            Assert.AreEqual(4843961d, startPoint.Y);

            ILineString endls = edges.GetGeometryN(141).GetGeometryN(0) as ILineString; ;
            Assert.IsNotNull(endls);
            IPoint endPoint = endls.StartPoint;
            Assert.AreEqual(2322739d, endPoint.X);
            Assert.AreEqual(4844539d, endPoint.Y);

            GraphBuilder2 builder = new GraphBuilder2(true);
            foreach (IMultiLineString mlstr in edges.Geometries)
            {
                Assert.AreEqual(1, mlstr.NumGeometries);
                ILineString str = mlstr.GetGeometryN(0) as ILineString;
                Assert.IsNotNull(str);
                Assert.IsTrue(builder.Add(str));
            }
            builder.Initialize();

            ILineString path = builder.Perform(startPoint, endPoint);
            Assert.IsNotNull(path);
            SaveGraphResult(path);

            ILineString reverse = builder.Perform(endPoint, startPoint);
            Assert.IsNotNull(reverse);
            Assert.AreEqual(path, reverse.Reverse());
        }
 public void CheckGraphBuilder2ExceptionUsingDifferentFactories()
 {
     GraphBuilder2 builder = new GraphBuilder2();
     Assert.IsTrue(builder.Add(a));
     Assert.IsTrue(builder.Add(b, c));
     Assert.IsTrue(builder.Add(d));
     builder.Add(GeometryFactory.Default.CreateLineString(new ICoordinate[]
     {
         new Coordinate(0 ,0),
         new Coordinate(50 , 50),
     }));
 }
 public void CheckGraphBuilder2ExceptionUsingDoubleInitialization()
 {
     GraphBuilder2 builder = new GraphBuilder2();
     builder.Add(a);
     builder.Add(b, c);
     builder.Add(d);
     builder.Add(e);
     builder.Initialize();
     builder.Initialize();
 }
 public void CheckGraphBuilder2ExceptionUsingARepeatedGeometry()
 {
     GraphBuilder2 builder = new GraphBuilder2();
     Assert.IsTrue(builder.Add(a));
     Assert.IsFalse(builder.Add(a));
     Assert.IsFalse(builder.Add(a, a));
     builder.Initialize();
 }
 public void CheckGraphBuilder2ExceptionUsingNoGeometries()
 {
     GraphBuilder2 builder = new GraphBuilder2();
     builder.Initialize();
 }
        public void TestBidirectionalGraphBuilder2WithSampleGeometries()
        {
            GraphBuilder2 builder = new GraphBuilder2(true);
            builder.Add(a);
            builder.Add(b, c);
            builder.Add(d);
            builder.Add(e);
            builder.Initialize();

            ILineString path = builder.Perform(start.Coordinate, end.Coordinate);
            Assert.IsNotNull(path);
            Assert.AreEqual(result, path);

            ILineString revpath = builder.Perform(end, start);
            Assert.IsNotNull(revpath);
            Assert.AreEqual(revresult, revpath);
        }
        public void TestGraphBuilder2WithSampleGeometries()
        {
            GraphBuilder2 builder = new GraphBuilder2();
            builder.Add(a);
            builder.Add(b, c);
            builder.Add(d);
            builder.Add(e);
            builder.Initialize();

            ILineString path = builder.Perform(start, end);
            Assert.IsNotNull(path);
            Assert.AreEqual(result, path);
        }        
 public void CheckGraphBuilder2ExceptionUsingOneGeometry()
 {
     var builder = new GraphBuilder2();
     Assert.IsTrue(builder.Add(a));
     builder.Initialize();
 }