Ejemplo n.º 1
0
        /// <summary>  Converts a MultiLineString to &lt;MultiLineString Text&gt;
        /// format, then appends it to the writer.
        ///
        /// </summary>
        /// <param name="multiLineString"> the MultiLineString to process
        /// </param>
        /// <param name="writer">          the output writer to append to
        /// </param>
        private void AppendMultiLineStringText(MultiLineString multiLineString,
                                               int level, bool indentFirst, TextWriter writer)
        {
            if (multiLineString.IsEmpty)
            {
                writer.Write(WktEmpty);
            }
            else
            {
                int  level2   = level;
                bool doIndent = indentFirst;
                writer.Write(WktLParan);

                int nCount = multiLineString.NumGeometries;
                for (int i = 0; i < nCount; i++)
                {
                    if (i > 0)
                    {
                        writer.Write(WktComma);
                        level2   = level + 1;
                        doIndent = true;
                    }
                    AppendLineStringText((LineString)multiLineString.GetGeometry(i),
                                         level2, doIndent, writer);
                }
                writer.Write(WktRParan);
            }
        }
Ejemplo n.º 2
0
        /// <summary> Tests whether a <see cref="Geometry"/> is sequenced correctly.
        /// <see cref="LineString"/>s are trivially sequenced.
        /// <see cref="MultiLineString"/>s are checked for correct sequencing.
        /// Otherwise, <code>isSequenced</code> is defined
        /// to be <see langword="true"/> for geometries that are not lineal.
        ///
        /// </summary>
        /// <param name="geom">the geometry to test
        /// </param>
        /// <returns> <see langword="true"/> if the geometry is sequenced or is not lineal
        /// </returns>
        public static bool IsSequenced(Geometry geom)
        {
            if (!(geom is MultiLineString))
            {
                return(true);
            }

            MultiLineString mls = (MultiLineString)geom;
            // the nodes in all subgraphs which have been completely scanned
            //TODO--PAUL 'java.util.TreeSet' was converted to ListSet
            ListSet prevSubgraphNodes = new ListSet();

            Coordinate lastNode  = null;
            IList      currNodes = new ArrayList();

            for (int i = 0; i < mls.NumGeometries; i++)
            {
                LineString line      = (LineString)mls.GetGeometry(i);
                Coordinate startNode = line.GetCoordinate(0);
                Coordinate endNode   = line.GetCoordinate(line.NumPoints - 1);

                // If this linestring is connected to a previous subgraph,
                // geom is not sequenced
                if (prevSubgraphNodes.Contains(startNode))
                {
                    return(false);
                }
                if (prevSubgraphNodes.Contains(endNode))
                {
                    return(false);
                }

                if (lastNode != null)
                {
                    if (!startNode.Equals(lastNode))
                    {
                        // start new connected sequence
                        prevSubgraphNodes.AddAll(currNodes);
                        currNodes.Clear();
                    }
                }

                currNodes.Add(startNode);
                currNodes.Add(endNode);
                lastNode = endNode;
            }

            return(true);
        }