public void GraphToGeometryConversionLinesTest() { Random random = new Random(); List <Coordinate> coordinates = new List <Coordinate>(); for (Int32 i = 0; i < 100; i++) { coordinates.Add(new Coordinate(i, i)); } GeometryGraph graph = new GeometryGraph(PrecisionModel.Default, _referenceSystemMock.Object, null); for (Int32 i = 0; i < coordinates.Count; i++) { graph.AddVertex(coordinates[i]); if (i > 0) { graph.AddEdge(graph.GetVertex(coordinates[i - 1]), graph.GetVertex(coordinates[i])); } } // only points Dictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, object>(); parameters[GraphOperationParameters.GeometryDimension] = 0; GraphToGeometryConversion conversion = new GraphToGeometryConversion(graph, parameters); conversion.Execute(); IGeometry result = conversion.Result; Assert.IsTrue(result is IMultiPoint); Assert.AreSame(result.ReferenceSystem, graph.ReferenceSystem); Assert.AreEqual(coordinates.Count, (result as IMultiPoint).Count); foreach (IPoint point in result as IMultiPoint) { Assert.IsTrue(coordinates.Contains(point.Coordinate)); } // only lines parameters = new Dictionary <OperationParameter, object>(); parameters[GraphOperationParameters.GeometryDimension] = 1; conversion = new GraphToGeometryConversion(graph, parameters); conversion.Execute(); result = conversion.Result; Assert.IsTrue(result is IMultiLineString); Assert.AreEqual(coordinates.Count - 1, (result as IMultiLineString).Count); foreach (ILineString lineString in result as IMultiLineString) { Assert.IsTrue(lineString is ILine); Assert.IsTrue(coordinates.Contains(lineString.StartCoordinate)); Assert.IsTrue(coordinates.Contains(lineString.EndCoordinate)); } // points and lines List <Coordinate> newCoordinates = new List <Coordinate>(); for (Int32 i = 100; i < 200; i++) { newCoordinates.Add(new Coordinate(i, i)); } newCoordinates.ForEach(coordinate => graph.AddVertex(coordinate)); parameters = new Dictionary <OperationParameter, object>(); parameters[GraphOperationParameters.GeometryDimension] = 1; conversion = new GraphToGeometryConversion(graph, parameters); conversion.Execute(); result = conversion.Result; Assert.IsTrue(result is IGeometryCollection <IGeometry>); Assert.AreEqual(coordinates.Count - 1 + newCoordinates.Count, (result as IGeometryCollection <IGeometry>).Count); foreach (IGeometry geometry in result as IGeometryCollection <IGeometry> ) { Assert.IsTrue(geometry is ILine || geometry is IPoint); if (geometry is ILine) { Assert.IsTrue(coordinates.Contains((geometry as ILine).StartCoordinate)); Assert.IsTrue(coordinates.Contains((geometry as ILine).EndCoordinate)); } if (geometry is IPoint) { Assert.IsTrue(newCoordinates.Contains((geometry as IPoint).Coordinate)); } } }