예제 #1
0
        /// <summary>
        /// Builds a geometry (<see cref="LineString" /> or <see cref="MultiLineString" />)
        /// representing the sequence.
        /// </summary>
        /// <param name="sequences">
        /// A <see cref="IList" /> of <see cref="IList" />s of <see cref="DirectedEdge" />s
        /// with <see cref="LineMergeEdge" />s as their parent edges.
        /// </param>
        /// <returns>
        /// The sequenced geometry, or <c>null</c> if no sequence exists.
        /// </returns>
        private IGeometry BuildSequencedGeometry(IList sequences)
        {
            IList lines = new ArrayList();

            IEnumerator i1 = sequences.GetEnumerator();

            while (i1.MoveNext())
            {
                IList       seq = (IList)i1.Current;
                IEnumerator i2  = seq.GetEnumerator();
                while (i2.MoveNext())
                {
                    DirectedEdge  de   = (DirectedEdge)i2.Current;
                    LineMergeEdge e    = (LineMergeEdge)de.Edge;
                    LineString    line = e.Line;

                    ILineString lineToAdd = line;
                    if (!de.EdgeDirection && !line.IsClosed)
                    {
                        lineToAdd = Reverse(line);
                    }

                    lines.Add(lineToAdd);
                }
            }
            if (lines.Count == 0)
            {
                return(factory.CreateMultiLineString(new LineString[0]));
            }
            return(new GeometryFactory(factory).BuildGeometry(lines));
        }
예제 #2
0
        /// <summary>
        /// Adds an Edge, DirectedEdges, and Nodes for the given LineString representation
        /// of an edge.
        /// </summary>
        public virtual void AddEdge(LineString lineString)
        {
            if (lineString.IsEmpty)
            {
                return;
            }
            ICoordinate[] coordinates     = CoordinateArrays.RemoveRepeatedPoints(lineString.Coordinates);
            ICoordinate   startCoordinate = coordinates[0];
            ICoordinate   endCoordinate   = coordinates[coordinates.Length - 1];
            Node          startNode       = GetNode(startCoordinate);
            Node          endNode         = GetNode(endCoordinate);
            DirectedEdge  directedEdge0   = new LineMergeDirectedEdge(startNode, endNode,
                                                                      coordinates[1], true);
            DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode,
                                                                   coordinates[coordinates.Length - 2], false);
            Edge edge = new LineMergeEdge(lineString);

            edge.SetDirectedEdges(directedEdge0, directedEdge1);
            Add(edge);
        }