public void TestBidirectionalGraphBuilder2WithSampleGeometries()
        {
            var builder = new GraphBuilder2(true);
            builder.Add(a);
            builder.Add(b, c);
            builder.Add(d);
            builder.Add(e);
            builder.Initialize();

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

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

            var path = builder.Perform(start, end);
            Assert.IsNotNull(path);
            Assert.AreEqual(result, path);
        }
 public void CheckGraphBuilder2ExceptionUsingNoGeometries()
 {
     var builder = new GraphBuilder2();
     builder.Initialize();
 }
 public void CheckGraphBuilder2ExceptionUsingOneGeometry()
 {
     var builder = new GraphBuilder2();
     Assert.IsTrue(builder.Add(a));
     builder.Initialize();
 }
 //[ExpectedException(typeof (ApplicationException))]
 public void CheckGraphBuilder2ExceptionUsingDoubleInitialization()
 {
     var builder = new GraphBuilder2();
     builder.Add(a);
     builder.Add(b, c);
     builder.Add(d);
     builder.Add(e);
     builder.Initialize();
     builder.Initialize();
 }
        public void BuildGraphFromStradeShapefile()
        {
            var shapepath = "strade_fixed.shp";
            var count = 703;

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

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

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

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

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

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

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

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

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

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

            var path = builder.Perform(startls.StartPoint, endls.EndPoint);
            Assert.IsNotNull(path);
        }
        public void BuildGraphFromCompleteGraphShapefile()
        {
            const string shapepath = "graph.shp";
            const int count = 1179;

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

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

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

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

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

            var reverse = builder.Perform(endPoint, startPoint);
            Assert.IsNotNull(reverse);
            Assert.AreEqual(path, reverse.Reverse());
        }
        /// <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, Coordinate src,
                                                                 Coordinate dst)
        {
            var 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);
        }